# Initiate ----
source("src/initiate.r")

# 2.0 Sample Demographics and Balance Tests ----
## 2.1 Sample Demographics ----
### Table A1: Sample Demographics ----
ds %>% 
  mutate(
    partyr = case_when(
      partyr == "dem" ~ "Dem",
      partyr == "rep" ~ "Rep",
      partyr == "ind" ~ "Ind"
    ),
    gender = case_when(
      gender == "male"  ~ "Man",
      gender == "female"  ~ "Woman"
    ),
    age = as.numeric(age), 
    education = case_when(
      education == "Less_than_Bachelors" ~ "Less than Bachelors", 
      education == "Bachelors_or_higher" ~ "Bachelors or higher"
    )
  ) %>% 
  dplyr::select(
    partyr, gender, age, white, black, asam,
    natam, rother, hisplat, education, income_cat
  ) %>% 
  tbl_summary(
    missing = "no",
    label = c(
      partyr ~ "Party", 
      gender ~ "Gender", 
      age ~ "Age", 
      white ~ "White",
      black ~ "Black",
      asam ~ "Asian American",
      natam ~ "Native American",
      rother ~ "Other Race",
      hisplat ~ "Hispanic/Latino",
      education ~ "Education",
      income_cat ~ "Income"
    )
  ) %>% 
  italicize_levels() %>%
  modify_header(label ~ "**Variable**") 

## 2.2 Balance Tests ----
### Table A2: Treatment Assignment Balance Tests ----
ds %>% 
  dplyr::select(
    partyr, par_treatment, partymatch, gender, age, white, black, asam,
    natam, rother, hisplat, education, income_cat, pos_treatment
  ) %>% 
  tbl_summary(
    by=pos_treatment, 
    missing = "no",
    label = c(
      partyr ~ "Party",
      par_treatment ~ "Randomized MC",
      partymatch ~ "Partisan Match",
      gender ~ "Gender",
      age ~ "Age",
      white ~ "White",
      black ~ "Black",
      asam ~ "Asian American",
      natam ~ "Native American",
      rother ~ "Other Race",
      hisplat ~ "Hispanic/Latino",
      education ~ "Education",
      income_cat ~ "Income"
    )
  ) %>% 
  italicize_levels() %>%
  modify_header(label ~ "**Variable**") 

# 3.0 Pairwise Comparisons ----
## 3.1 Pairwise T-tests ----
### Table A3: Difference in Means ----
t.test(
  ds$effective[ds$pos_treatment == "control"],
  ds$effective[ds$pos_treatment == "nocom"]
) 

t.test(
  ds$money[ds$pos_treatment == "control"],
  ds$money[ds$pos_treatment == "nocom"]
)

t.test(
  ds$therm[ds$pos_treatment == "control"],
  ds$therm[ds$pos_treatment == "nocom"]
)

t.test(
  ds$pleased[ds$pos_treatment == "control"],
  ds$pleased[ds$pos_treatment == "nocom"]
)

### Table A4: Difference in Means ----
t.test(
  ds$effective[ds$pos_treatment == "nocom"],
  ds$effective[ds$pos_treatment == "commem"]
)

t.test(
  ds$money[ds$pos_treatment == "nocom"],
  ds$money[ds$pos_treatment == "commem"]
)

t.test(
  ds$therm[ds$pos_treatment == "nocom"],
  ds$therm[ds$pos_treatment == "commem"]
)

t.test(
  ds$pleased[ds$pos_treatment == "nocom"],
  ds$pleased[ds$pos_treatment == "commem"]
)

### Table A5: Difference in Means ----
t.test(
  ds$effective[ds$pos_treatment == "nocom"],
  ds$effective[ds$pos_treatment == "comlead"]
)

t.test(
  ds$money[ds$pos_treatment == "nocom"],
  ds$money[ds$pos_treatment == "comlead"]
)

t.test(
  ds$therm[ds$pos_treatment == "nocom"],
  ds$therm[ds$pos_treatment == "comlead"]
)

t.test(
  ds$pleased[ds$pos_treatment == "nocom"],
  ds$pleased[ds$pos_treatment == "comlead"]
)

### Table A6: Difference in Means ----
t.test(
  ds$effective[ds$pos_treatment == "commem"],
  ds$effective[ds$pos_treatment == "comlead"]
)

t.test(
  ds$money[ds$pos_treatment == "commem"],
  ds$money[ds$pos_treatment == "comlead"]
)

t.test(
  ds$therm[ds$pos_treatment == "commem"],
  ds$therm[ds$pos_treatment == "comlead"]
)

t.test(
  ds$pleased[ds$pos_treatment == "commem"],
  ds$pleased[ds$pos_treatment == "comlead"]
)

## 3.2 ANOVA with Tukey Corrections ----
### Table A7: ANOVA with Tukey Correction, DV = Effective ----
summary(
  glht(
    aov(
      effective ~ pos_treatment,
      ds %>% filter(pos_treatment != "control")
    ),
    linfct = mcp(pos_treatment = "Tukey")
  )
)

### Table A8: ANOVA with Tukey Correction, DV = Money ----
summary(
  glht(
    aov(
      money ~ pos_treatment,
      ds %>% filter(pos_treatment != "control")
    ),
    linfct = mcp(pos_treatment = "Tukey")
  )
)

### Table A9: ANOVA with Tukey Correction, DV = Thermometer ----
summary(
  glht(
    aov(
      therm ~ pos_treatment,
      ds %>% filter(pos_treatment != "control")
    ),
    linfct = mcp(pos_treatment = "Tukey")
  )
)

### Table A10: ANOVA with Tukey Correction, DV = Pleased ----
summary(
  glht(
    aov(
      pleased ~ pos_treatment,
      ds %>% filter(pos_treatment != "control")
    ),
    linfct = mcp(pos_treatment = "Tukey")
  )
)

# 4.0 Regression Tables with Covariate Estimates ----
### Table A11: Average Treatment Effects (OLS) on MC Effectiveness ----
summary(
  lm(
    effective ~ 
      pos_treatment_ref + partymatch + partyr2 + 
      white + black + hisplat + asam + natam + rother + 
      poly(age, 2, raw = TRUE) + gender + edu + ideo + income,
    data = ds
  )
)

summary(
  lm(
    money ~ 
      pos_treatment_ref + partymatch + partyr2 + 
      white + black + hisplat + asam + natam + rother + 
      poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
    data = ds
  )
)

### Table A12: Average Treatment Effects (OLS) on MC Support ----
summary(
  lm(
    therm ~ 
      pos_treatment_ref + partymatch + partyr2 + 
      white + black + hisplat + asam + natam + rother + 
      poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
    data = ds
  )
)

summary(
  lm(
    pleased ~ 
      pos_treatment_ref + partymatch + partyr2 + 
      white + black + hisplat + asam + natam + rother + 
      poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
    data = ds
  )
)

# 5.0 Analyses by Partisan Subset ----
## 5.1 Mean Visualizations ----
### Figure A1: Mean Values by Treatment (Passing Legislation) ----
ds %>%
  drop_na(pos_treatment, effective) %>%
  group_by(pos_treatment, partyr2) %>%
  summarise(
    nrow = length(effective), 
    mean = mean(effective), 
    se = sd(effective) / sqrt(nrow),
    ci = 1.96 * se,
    lower_ci = mean - ci,
    upper_ci = mean + ci) %>% 
  mutate(
    partyr2 = case_when(
      partyr2 == "dem" ~ "Democratic Respondents", 
      partyr2 == "rep" ~ "Republican Respondents"
    )
  ) %>%
  ggplot(., aes(x = pos_treatment, y = mean, color = partyr2)) + 
  geom_pointrange(
    aes(
      ymin = mean - ci, 
      ymax = mean + ci
    ), 
    position = position_dodge(width = .5), 
    size = 1, 
    linewidth = 1
  ) + 
  labs(
    y = "Effectiveness Rating (1-7)",
    title = "", 
    caption = "\n\n“How effective do you think Rep. Luke Philips is at passing legislation that helps his community?”"
  ) +
  scale_color_manual(values = c("mediumblue", "red3"), guide = "none") +
  facet_wrap(~ partyr2) +
  scale_x_discrete(
    labels = c(
      "control" = "Control \n", 
      "nocom" = "No \nSubcommittee", 
      "commem" = "Subcommittee \nMember",
      "comlead" = "Subcommittee \nLeader"
    )
  ) +
  scale_y_continuous(limits = c(3.5, 5.5))

### Figure A2: Mean Values by Treatment (Securing Funding) ----
ds %>%
  drop_na(pos_treatment, money) %>%
  group_by(pos_treatment, partyr2) %>%
  summarise(
    nrow = length(money), 
    mean = mean(money), 
    se = sd(money) / sqrt(nrow),
    ci = 1.96 * se,
    lower_ci = mean - ci,
    upper_ci = mean + ci) %>% 
  mutate(
    partyr2 = case_when(
      partyr2 == "dem" ~ "Democratic Respondents", 
      partyr2 == "rep" ~ "Republican Respondents"
    )
  ) %>%
  ggplot(., aes(x = pos_treatment, y = mean, color = partyr2)) + 
  geom_pointrange(
    aes(
      ymin = mean - ci, 
      ymax = mean + ci
    ), 
    position = position_dodge(width = .5), 
    size = 1, 
    linewidth = 1
  ) + 
  labs(
    y = "Securing Funding Rating (1-7)",
    title = "", 
    caption = "\n\n“How effective do you think Rep. Luke Philips is at bringing home federal money to his district?”"
  ) +
  scale_color_manual(values = c("mediumblue", "red3"), guide = "none") +
  facet_wrap(~ partyr2) +
  scale_x_discrete(
    labels = c(
      "control" = "Control \n", 
      "nocom" = "No \nSubcommittee", 
      "commem" = "Subcommittee \nMember",
      "comlead" = "Subcommittee \nLeader"
    )
  ) +
  scale_y_continuous(limits = c(3.5, 5.5))

### Figure A3: Mean Values by Treatment (Thermometer) ----
ds %>%
  drop_na(pos_treatment, therm) %>%
  group_by(pos_treatment, partyr2) %>%
  summarise(
    nrow = length(therm), 
    mean = mean(therm), 
    se = sd(therm) / sqrt(nrow),
    ci = 1.96 * se,
    lower_ci = mean - ci,
    upper_ci = mean + ci) %>% 
  mutate(
    partyr2 = case_when(
      partyr2 == "dem" ~ "Democratic Respondents", 
      partyr2 == "rep" ~ "Republican Respondents"
    )
  ) %>%
  ggplot(., aes(x = pos_treatment, y = mean, color = partyr2)) + 
  geom_pointrange(
    aes(
      ymin = mean - ci, 
      ymax = mean + ci
    ), 
    position = position_dodge(width = .5), 
    size = 1, 
    linewidth = 1
  ) + 
  labs(
    y = "Thermometer Rating (0-100)",
    title = "", 
    caption = "\n\n“How do you feel about Rep. Luke Philips?”") +
  scale_color_manual(values = c("mediumblue", "red3"), guide = "none") +
  facet_wrap(~ partyr2) +
  scale_x_discrete(
    labels = c(
      "control" = "Control \n", 
      "nocom" = "No \nSubcommittee", 
      "commem" = "Subcommittee \nMember",
      "comlead" = "Subcommittee \nLeader"
    )
  ) +
  scale_y_continuous(limits = c(50, 70))

### Figure A4: Mean Values by Treatment (Pleased) ----
ds %>%
  drop_na(pos_treatment, pleased) %>%
  group_by(pos_treatment, partyr2) %>%
  summarise(
    nrow = length(pleased), 
    mean = mean(pleased), 
    se = sd(pleased) / sqrt(nrow),
    ci = 1.96 * se,
    lower_ci = mean - ci,
    upper_ci = mean + ci) %>% 
  mutate(
    partyr2 = case_when(
      partyr2 == "dem" ~ "Democratic Respondents", 
      partyr2 == "rep" ~ "Republican Respondents"
    )
  ) %>%
  ggplot(., aes(x = pos_treatment, y = mean, color = partyr2)) + 
  geom_pointrange(
    aes(
      ymin = mean - ci, 
      ymax = mean + ci
    ), 
    position = position_dodge(width = .5), 
    size = 1, 
    linewidth = 1
  ) + 
  labs(
    y = "Pleased Rating (1-7)",
    title = "", 
    caption = "\n\n“How pleased would you be if Rep. Luke Philips was your representative in Congress?”") +
  scale_color_manual(values = c("mediumblue", "red3"), guide = "none") +
  facet_wrap(~ partyr2) +
  scale_x_discrete(
    labels = c(
      "control" = "Control \n", 
      "nocom" = "No \nSubcommittee", 
      "commem" = "Subcommittee \nMember",
      "comlead" = "Subcommittee \nLeader"
    )
  ) +
  scale_y_continuous(limits = c(3.5, 5.5))

## 5.2 ANOVA with Tukey Corrections (Democratic Subsample) ----
### Table A13: Anova with Tukey Correction, DV = Effective ----
summary(
  glht(
    aov(
      effective ~ pos_treatment,
      ds %>% filter(pos_treatment != "control" & partyr2 == "dem")
    ),
    linfct = mcp(pos_treatment = "Tukey")
  )
)

### Table A14: Anova with Tukey Correction, DV = Money ----
summary(
  glht(
    aov(
      money ~ pos_treatment,
      ds %>% filter(pos_treatment != "control" & partyr2 == "dem")
    ),
    linfct = mcp(pos_treatment = "Tukey")
  )
)
### Table A15: Anova with Tukey Correction, DV = Thermometer ----
summary(
  glht(
    aov(
      therm ~ pos_treatment,
      ds %>% filter(pos_treatment != "control" & partyr2 == "dem")
    ),
    linfct = mcp(pos_treatment = "Tukey")
  )
)
### Table A16: Anova with Tukey Correction, DV = Pleased ----
summary(
  glht(
    aov(
      pleased ~ pos_treatment,
      ds %>% filter(pos_treatment != "control" & partyr2 == "dem")
    ),
    linfct = mcp(pos_treatment = "Tukey")
  )
)
## 5.3 ANOVA with Tukey Corrections (Republican Subsample) ----
### Table A17: Anova with Tukey Correction, DV = Effective ----
summary(
  glht(
    aov(
      effective ~ pos_treatment,
      ds %>% filter(pos_treatment != "control" & partyr2 == "rep")
    ),
    linfct = mcp(pos_treatment = "Tukey")
  )
)

### Table A18: Anova with Tukey Correction, DV = Money ----
summary(
  glht(
    aov(
      money ~ pos_treatment,
      ds %>% filter(pos_treatment != "control" & partyr2 == "rep")
    ),
    linfct = mcp(pos_treatment = "Tukey")
  )
)

### Table A19: Anova with Tukey Correction, DV = Thermometer ----
summary(
  glht(
    aov(
      therm ~ pos_treatment,
      ds %>% filter(pos_treatment != "control" & partyr2 == "rep")
    ),
    linfct = mcp(pos_treatment = "Tukey")
  )
)

### Table A20: Anova with Tukey Correction, DV = Pleased ----
summary(
  glht(
    aov(
      pleased ~ pos_treatment,
      ds %>% filter(pos_treatment != "control" & partyr2 == "rep")
    ),
    linfct = mcp(pos_treatment = "Tukey")
  )
)

## 5.4 Regression Models with Partisan Interactions ----
### Table A21:  Average Treatment Effects with Interaction ----
summary(
  lm(
    effective ~ 
      pos_treatment_ref * partyr2 + partymatch + 
      white + black + hisplat + asam + natam + rother + 
      poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
    data = ds
  )
)

summary(
  lm(
    money ~ 
      pos_treatment_ref * partyr2 + partymatch + 
      white + black + hisplat + asam + natam + rother + 
      poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
    data = ds
  )
)

summary(
  lm(
    therm ~ 
      pos_treatment_ref * partyr2 + partymatch + 
      white + black + hisplat + asam + natam + rother + 
      poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
    data = ds
  )
)

summary(
  lm(
    pleased ~ 
      pos_treatment_ref * partyr2 + partymatch + 
      white + black + hisplat + asam + natam + rother + 
      poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
    data = ds
  )
)

# 6.0 Additional Analyses ----
## 6.1 Attention Check Coverage ----
### Table A22: Demographic Profiles of Respondents who Pass/Fail ----
ds_ac %>% 
  mutate(
    gender = case_when(
      gender == "male" ~ "Man",
      gender == "female"  ~ "Woman"
    ),
    age = as.numeric(age), 
    education = case_when(
      education == "Less_than_Bachelors" ~ "Less than Bachelors", 
      education == "Bachelors_or_higher" ~ "Bachelors or higher"
    )
  ) %>% 
  dplyr::select(
    pp, gender, age, white, black, asam, natam,
    rother, hisplat, education, income_cat, ac
  ) %>% 
  tbl_summary(
    missing = "no",
    by = "ac",
    label = c(
      pp ~ "Party",
      gender ~ "Gender",
      age ~ "Age",
      white ~ "White",
      black ~ "Black",
      asam ~ "Asian American",
      natam ~ "Native American",
      rother ~ "Other Race",
      hisplat ~ "Hispanic/Latino",
      education ~ "Education",
      income_cat ~ "Income"
    )
  ) %>% 
  italicize_levels() %>%
  modify_header(label ~ "**Variable**") 

### Figure A5: Distribution of Survey Duration ----
cut <- quantile(ds$duration, probs = c(.05, .95))
cut2 <- quantile(ds$duration, probs = c(.1, .9))

ds %>% 
  ggplot(.) +
  geom_histogram(
    aes(duration, after_stat(density)), 
    color = "grey60", 
    fill = "grey90", 
    alpha = .5
  ) +
  geom_density(
    aes(duration), 
    linewidth = 1, 
    color = alpha("black", .55)
  ) +
  geom_vline(xintercept = cut[[1]], color = "#8494FF", linewidth = 1.25) +
  geom_vline(xintercept = cut[[2]], color = "#8494FF", linewidth = 1.25) +
  geom_vline(xintercept = cut2[[1]], color = "#E69F00", linewidth = 1.25) +
  geom_vline(xintercept = cut2[[2]], color = "#E69F00", linewidth = 1.25) +
  scale_x_log10() +
  labs(x = "Log of Duration (s)", y = "Density")

### Figure A6: Treatment Coefficients with Duration Exclusion ----
dsalt <- ds %>% filter(duration > cut[[1]], duration < cut[[2]])
dsalt2 <- ds %>% filter(duration > cut2[[1]], duration < cut2[[2]])

summary(
  mod1.2 <- 
    lm(
      effective ~ 
        pos_treatment_ref + partymatch + partyr2 + 
        white + black + hisplat + asam + natam + rother + 
        poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
      data = ds
    )
)

summary(
  mod2.2 <- 
    lm(
      money ~ 
        pos_treatment_ref + partymatch + partyr2 + 
        white + black + hisplat + asam + natam + rother + 
        poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
      data = ds
    )
)

summary(
  mod3.2 <- 
    lm(
      therm ~ 
        pos_treatment_ref + partymatch + partyr2 + 
        white + black + hisplat + asam + natam + rother + 
        poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
      data = ds
    )
)

summary(
  mod4.2 <- 
    lm(
      pleased ~ 
        pos_treatment_ref + partymatch + partyr2 + 
        white + black + hisplat + asam + natam + rother + 
        poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
      data = ds
    )
)

summary(
  mod1.2alt <- 
    lm(
      effective ~ 
        pos_treatment_ref + partymatch + partyr2 + 
        white + black + hisplat + asam + natam + rother + 
        poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
      data = dsalt
    )
)

summary(
  mod2.2alt <- 
    lm(
      money ~ 
        pos_treatment_ref + partymatch + partyr2 + 
        white + black + hisplat + asam + natam + rother + 
        poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
      data = dsalt
    )
)

summary(
  mod3.2alt <- 
    lm(
      therm ~ 
        pos_treatment_ref + partymatch + partyr2 + 
        white + black + hisplat + asam + natam + rother + 
        poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
      data = dsalt
    )
)

summary(
  mod4.2alt <- 
    lm(
      pleased ~ 
        pos_treatment_ref + partymatch + partyr2 + 
        white + black + hisplat + asam + natam + rother + 
        poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
      data = dsalt
    )
)

summary(
  mod1.2alt2 <- 
    lm(
      effective ~ 
        pos_treatment_ref + partymatch + partyr2 + 
        white + black + hisplat + asam + natam + rother + 
        poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
      data = dsalt2
    )
)

summary(
  mod2.2alt2 <- 
    lm(
      money ~ pos_treatment_ref + partymatch + partyr2 + 
        white + black + hisplat + asam + natam + rother + 
        poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
      data = dsalt2
    )
)

summary(
  mod3.2alt2 <- 
    lm(
      therm ~ pos_treatment_ref + partymatch + partyr2 + 
        white + black + hisplat + asam + natam + rother + 
        poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
      data = dsalt2
    )
)

summary(
  mod4.2alt2 <- 
    lm(
      pleased ~ pos_treatment_ref + partymatch + partyr2 + 
        white + black + hisplat + asam + natam + rother + 
        poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
      data = dsalt2
    )
)

data.frame(
  "var" = rep(
    c(
      "Control\n(No Credit Claim)", 
      "Subcommittee\nMember", 
      "Subcommittee\nLeader"), 
    36
  ), 
  "sample" = rep(
    c(
      rep("Full Sample", 3), 
      rep("95% Duration", 3), 
      rep("90% Duration", 3)
    ), 
    4
  ),
  "dv" = c(
    rep("Passing Legislation (1-7)", 9), 
    rep("Securing Funding (1-7)", 9), 
    rep("Feeling Thermometer (0-100)", 9), 
    rep("Pleased Rating (1-7)", 9)
  ), 
  "est" = c(
    as.numeric(summary(mod1.2)$coefficients[2:4, 1]),
    as.numeric(summary(mod1.2alt)$coefficients[2:4, 1]), 
    as.numeric(summary(mod1.2alt2)$coefficients[2:4, 1]), 
    as.numeric(summary(mod2.2)$coefficients[2:4, 1]),
    as.numeric(summary(mod2.2alt)$coefficients[2:4, 1]), 
    as.numeric(summary(mod2.2alt2)$coefficients[2:4, 1]),
    as.numeric(summary(mod3.2)$coefficients[2:4, 1]),
    as.numeric(summary(mod3.2alt)$coefficients[2:4, 1]), 
    as.numeric(summary(mod3.2alt2)$coefficients[2:4, 1]),
    as.numeric(summary(mod4.2)$coefficients[2:4, 1]),
    as.numeric(summary(mod4.2alt)$coefficients[2:4, 1]), 
    as.numeric(summary(mod4.2alt2)$coefficients[2:4, 1])
  ), 
  "se" = c(
    as.numeric(summary(mod1.2)$coefficients[2:4, 2]),
    as.numeric(summary(mod1.2alt)$coefficients[2:4, 2]), 
    as.numeric(summary(mod1.2alt2)$coefficients[2:4, 2]), 
    as.numeric(summary(mod2.2)$coefficients[2:4, 2]),
    as.numeric(summary(mod2.2alt)$coefficients[2:4, 2]), 
    as.numeric(summary(mod2.2alt2)$coefficients[2:4, 2]),
    as.numeric(summary(mod3.2)$coefficients[2:4, 2]),
    as.numeric(summary(mod3.2alt)$coefficients[2:4, 2]), 
    as.numeric(summary(mod3.2alt2)$coefficients[2:4, 2]),
    as.numeric(summary(mod4.2)$coefficients[2:4, 2]),
    as.numeric(summary(mod4.2alt)$coefficients[2:4, 2]), 
    as.numeric(summary(mod4.2alt2)$coefficients[2:4, 2])
  )
) %>% 
  mutate(lb = est - 1.96 * se, ub = est + 1.96 * se) %>%
  mutate(
    var = factor(
      var, 
      levels = c(
        "Subcommittee\nLeader", 
        "Subcommittee\nMember", 
        "Control\n(No Credit Claim)"
      )
    ), 
    dv = factor(
      dv, 
      levels = c(
        "Passing Legislation (1-7)",
        "Securing Funding (1-7)",
        "Feeling Thermometer (0-100)",
        "Pleased Rating (1-7)"
      )
    )
  ) %>%
  ggplot() +
  geom_hline(yintercept = 0, linetype = "dashed") +
  geom_pointrange(
    aes(
      x = var, 
      y = est, 
      ymin = lb, 
      ymax = ub, 
      color = sample, 
      shape = sample
    ),
    position = position_dodge(width = .25)
  ) + 
  facet_wrap(.~dv, scales = "free", ncol = 1, strip.position = "left") +
  scale_x_discrete(position = "top") +
  ggh4x::facetted_pos_scales(
    y = list(
      scale_y_continuous(limits = c(-1.1, 1.1), breaks = seq(-1, 1, .5)),
      scale_y_continuous(limits = c(-1.1, 1.1), breaks = seq(-1, 1, .5)),
      scale_y_continuous(limits = c(-10, 10), breaks = seq(-10, 10, 5)),
      scale_y_continuous(limits = c(-1.1, 1.1), breaks = seq(-1, 1, .5))
    )
  ) +
  coord_flip() +
  guides(
    color = guide_legend(reverse = TRUE), 
    shape = guide_legend(reverse = TRUE)
  ) +
  labs(color = "", shape = "", group = "", x = "", y = "Estimates")

## 6.2 Estimating the Population Average Treatment Effect ----
### Figure A7: Discrepancy between Sample and Target Demographics ----
#### Gender
gender_ps_male <- 
  sum(poststrat_df$n[poststrat_df$SEX == "male"]) / sum(poststrat_df$n)
gender_ps_female <- 
  sum(poststrat_df$n[poststrat_df$SEX == "female"]) / sum(poststrat_df$n)
gender_df_male <- 
  sum(ds_weight$gender == "male") / nrow(ds_weight)
gender_df_female <- 
  sum(ds_weight$gender == "female") / nrow(ds_weight)

ggplot() + 
  geom_bar(
    aes(x = "2", y = gender_ps_male), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x= .1), width = .2
  ) + 
  geom_bar(
    aes(x = "1", y = gender_ps_female), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x= .1), width = .2
  ) + 
  geom_bar(
    aes(x = "2", y = gender_df_male), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.1), width = .2
  ) + 
  geom_bar(
    aes(x = "1", y = gender_df_female), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.1), width = .2
  ) + 
  geom_text(
    aes(x = "1", y = gender_ps_female), 
    label = paste0(round(gender_ps_female, 2)), 
    position = position_nudge(x = .1, y = .03)
  ) + 
  geom_text(
    aes(x = "2", y = gender_ps_male), 
    label = paste0(round(gender_ps_male, 2)), 
    position = position_nudge(x = .1, y = .03)
  ) + 
  geom_text(
    aes(x = "1", y = gender_df_female), 
    label = paste0(round(gender_df_female, 2)), 
    position = position_nudge(x = -.1, y = .03)
  ) + 
  geom_text(
    aes(x = "2", y = gender_df_male), 
    label = paste0(round(gender_df_male, 2)), 
    position = position_nudge(x = -.1, y = .03)
  ) + 
  scale_x_discrete(labels = c("Female", "Male")) + 
  scale_y_continuous(limits = c(0, 1)) + 
  labs(x = "", y = "proportion")

#### Education
edu_ps_bh <- 
  sum(poststrat_df$n[poststrat_df$SCHL == "Bachelors_or_higher"]) / 
  sum(poststrat_df$n)
edu_ps_lb <- 
  sum(poststrat_df$n[poststrat_df$SCHL == "Less_than_Bachelors"]) / 
  sum(poststrat_df$n)
edu_df_bh <- 
  sum(ds_weight$edu == "Bachelors_or_higher") / nrow(ds_weight)
edu_df_lb <- 
  sum(ds_weight$edu == "Less_than_Bachelors") / nrow(ds_weight)

ggplot() + 
  geom_bar(
    aes(x = "2", y = edu_ps_bh), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x= .1), width = .2
  ) + 
  geom_bar(
    aes(x = "1", y = edu_ps_lb), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x= .1), width = .2
  ) + 
  geom_bar(
    aes(x = "2", y = edu_df_bh), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.1), width = .2
  ) + 
  geom_bar(
    aes(x = "1", y = edu_df_lb), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.1), width = .2
  ) + 
  geom_text(
    aes(x = "2", y = edu_ps_bh), 
    label = paste0(round(edu_ps_bh, 2)), 
    position = position_nudge(x = .1, y = .03)
  ) + 
  geom_text(
    aes(x = "1", y = edu_ps_lb), 
    label = paste0(round(edu_ps_lb, 2)), 
    position = position_nudge(x = .1, y = .03)
  ) + 
  geom_text(
    aes(x = "2", y = edu_df_bh), 
    label = paste0(round(edu_df_bh, 2)), 
    position = position_nudge(x = -.1, y = .03)
  ) + 
  geom_text(
    aes(x = "1", y = edu_df_lb), 
    label = paste0(round(edu_df_lb, 2)), 
    position = position_nudge(x = -.1, y = .03)) + 
  scale_x_discrete(labels = c("Less than Bachelors", "Bachelors or higher")) + 
  scale_y_continuous(limits = c(0, 1)) + 
  labs(x = "", y = "proportion")

#### White
white_ps_1 <- 
  sum(poststrat_df$n[poststrat_df$RACWHT == 1]) / sum(poststrat_df$n)
white_ps_0 <- 
  sum(poststrat_df$n[poststrat_df$RACWHT == 0]) / sum(poststrat_df$n)
white_df_1 <- 
  sum(ds_weight$white == 1) / nrow(ds_weight)
white_df_0 <- 
  sum(ds_weight$white == 0) / nrow(ds_weight)

ggplot() + 
  geom_bar(
    aes(x = "1", y = white_ps_1), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x= .1), width = .2
  ) + 
  geom_bar(
    aes(x = "2", y = white_ps_0), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x= .1), width = .2
  ) + 
  geom_bar(
    aes(x = "1", y = white_df_1), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.1), width = .2
  ) + 
  geom_bar(
    aes(x = "2", y = white_df_0), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.1), width = .2
  ) + 
  geom_text(
    aes(x = "1", y = white_ps_1), 
    label = paste0(round(white_ps_1, 2)), 
    position = position_nudge(x = .1, y = .03)
  ) + 
  geom_text(
    aes(x = "2", y = white_ps_0), 
    label = paste0(round(white_ps_0, 2)), 
    position = position_nudge(x = .1, y = .03)
  ) + 
  geom_text(
    aes(x = "1", y = white_df_1), 
    label = paste0(round(white_df_1, 2)), 
    position = position_nudge(x = -.1, y = .03)
  ) + 
  geom_text(
    aes(x = "2", y = white_df_0), 
    label = paste0(round(white_df_0, 2)), 
    position = position_nudge(x = -.1, y = .03)
  ) + 
  scale_x_discrete(labels = c("White", "Not white")) + 
  scale_y_continuous(limits = c(0, 1)) + 
  labs(x = "", y = "proportion")

#### Black
black_ps_1 <- 
  sum(poststrat_df$n[poststrat_df$RACBLK == 1]) / sum(poststrat_df$n)
black_ps_0 <- 
  sum(poststrat_df$n[poststrat_df$RACBLK == 0]) / sum(poststrat_df$n)
black_df_1 <- 
  sum(ds_weight$black == 1) / nrow(ds_weight)
black_df_0 <- 
  sum(ds_weight$black == 0) / nrow(ds_weight)

ggplot() + 
  geom_bar(
    aes(x = "1", y = black_ps_1), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x= .1), width = .2
  ) + 
  geom_bar(
    aes(x = "2", y = black_ps_0), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x= .1), width = .2
  ) + 
  geom_bar(
    aes(x = "1", y = black_df_1), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.1), width = .2
  ) + 
  geom_bar(
    aes(x = "2", y = black_df_0), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.1), width = .2
  ) + 
  geom_text(
    aes(x = "1", y = black_ps_1), 
    label = paste0(round(black_ps_1, 2)), 
    position = position_nudge(x = .1, y = .03)
  ) + 
  geom_text(
    aes(x = "2", y = black_ps_0), 
    label = paste0(round(black_ps_0, 2)), 
    position = position_nudge(x = .1, y = .03)
  ) + 
  geom_text(
    aes(x = "1", y = black_df_1), 
    label = paste0(round(black_df_1, 2)), 
    position = position_nudge(x = -.1, y = .03)
  ) + 
  geom_text(
    aes(x = "2", y = black_df_0), 
    label = paste0(round(black_df_0, 2)), 
    position = position_nudge(x = -.1, y = .03)
  ) + 
  scale_x_discrete(labels = c("Black", "Not black")) + 
  scale_y_continuous(limits = c(0, 1)) + 
  labs(x = "", y = "proportion")

#### Asian American
asam_ps_1 <- 
  sum(poststrat_df$n[poststrat_df$RACASN == 1]) / sum(poststrat_df$n)
asam_ps_0 <- 
  sum(poststrat_df$n[poststrat_df$RACASN == 0]) / sum(poststrat_df$n)
asam_df_1 <- 
  sum(ds_weight$asam == 1) / nrow(ds_weight)
asam_df_0 <- 
  sum(ds_weight$asam == 0) / nrow(ds_weight)

ggplot() + 
  geom_bar(
    aes(x = "1", y = asam_ps_1), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x= .1), width = .2
  ) + 
  geom_bar(
    aes(x = "2", y = asam_ps_0), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x= .1), width = .2
  ) + 
  geom_bar(
    aes(x = "1", y = asam_df_1), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.1), width = .2
  ) + 
  geom_bar(
    aes(x = "2", y = asam_df_0), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.1), width = .2
  ) + 
  geom_text(
    aes(x = "1", y = asam_ps_1), 
    label = paste0(round(asam_ps_1, 2)), 
    position = position_nudge(x = .1, y = .03)
  ) + 
  geom_text(
    aes(x = "2", y = asam_ps_0), 
    label = paste0(round(asam_ps_0, 2)), 
    position = position_nudge(x = .1, y = .03)
  ) + 
  geom_text(
    aes(x = "1", y = asam_df_1), 
    label = paste0(round(asam_df_1, 2)), 
    position = position_nudge(x = -.1, y = .03)
  ) + 
  geom_text(
    aes(x = "2", y = asam_df_0), 
    label = paste0(round(asam_df_0, 2)), 
    position = position_nudge(x = -.1, y = .03)
  ) + 
  scale_x_discrete(labels = c("Asian American", "Not Asian American")) + 
  scale_y_continuous(limits = c(0, 1)) + 
  labs(x = "", y = "proportion")

#### Native American
natam_ps_1 <- 
  sum(poststrat_df$n[poststrat_df$RACAIAN == 1]) / sum(poststrat_df$n)
natam_ps_0 <- 
  sum(poststrat_df$n[poststrat_df$RACAIAN == 0]) / sum(poststrat_df$n)
natam_df_1 <- 
  sum(ds_weight$natam == 1) / nrow(ds_weight)
natam_df_0 <- 
  sum(ds_weight$natam == 0) / nrow(ds_weight)

ggplot() + 
  geom_bar(
    aes(x = "1", y = natam_ps_1), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x= .1), width = .2
  ) + 
  geom_bar(
    aes(x = "2", y = natam_ps_0), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x= .1), width = .2
  ) + 
  geom_bar(
    aes(x = "1", y = natam_df_1), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.1), width = .2
  ) + 
  geom_bar(
    aes(x = "2", y = natam_df_0), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.1), width = .2
  ) + 
  geom_text(
    aes(x = "1", y = natam_ps_1), 
    label = paste0(round(natam_ps_1, 2)), 
    position = position_nudge(x = .1, y = .03)
  ) + 
  geom_text(
    aes(x = "2", y = natam_ps_0), 
    label = paste0(round(natam_ps_0, 2)), 
    position = position_nudge(x = .28)
  ) + 
  geom_text(
    aes(x = "1", y = natam_df_1), 
    label = paste0(round(natam_df_1, 2)), 
    position = position_nudge(x = -.1, y = .03)
  ) + 
  geom_text(
    aes(x = "2", y = natam_df_0), 
    label = paste0(round(natam_df_0, 2)), position = position_nudge(x = -.28)) + 
  scale_x_discrete(labels = c("Native American", "Not Native American")) + 
  scale_y_continuous(limits = c(0, 1)) + 
  labs(x = "", y = "proportion")

#### Other race
rother_ps_1 <- 
  sum(poststrat_df$n[poststrat_df$RACSOR == 1]) / sum(poststrat_df$n)
rother_ps_0 <- 
  sum(poststrat_df$n[poststrat_df$RACSOR == 0]) / sum(poststrat_df$n)
rother_df_1 <-
  sum(ds_weight$rother == 1) / nrow(ds_weight)
rother_df_0 <- 
  sum(ds_weight$rother == 0) / nrow(ds_weight)

ggplot() + 
  geom_bar(
    aes(x = "1", y = rother_ps_1), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x= .1), width = .2
  ) + 
  geom_bar(
    aes(x = "2", y = rother_ps_0), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x= .1), width = .2
  ) + 
  geom_bar(
    aes(x = "1", y = rother_df_1), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.1), width = .2
  ) + 
  geom_bar(
    aes(x = "2", y = rother_df_0), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.1), width = .2
  ) + 
  geom_text(
    aes(x = "1", y = rother_ps_1), 
    label = paste0(round(rother_ps_1, 2)), 
    position = position_nudge(x = .1, y = .03)
  ) + 
  geom_text(
    aes(x = "2", y = rother_ps_0), 
    label = paste0(round(rother_ps_0, 2)), 
    position = position_nudge(x = .1, y = 0.03)
  ) + 
  geom_text(
    aes(x = "1", y = rother_df_1), 
    label = paste0(round(rother_df_1, 2)), 
    position = position_nudge(x = -.1, y = .03)
  ) + 
  geom_text(
    aes(x = "2", y = rother_df_0), 
    label = paste0(round(rother_df_0, 2)), 
    position = position_nudge(x = -.28)
  ) + 
  scale_x_discrete(labels = c("Other race", "Not other race")) + 
  scale_y_continuous(limits = c(0, 1)) + 
  labs(x = "", y = "proportion")

#### Hispanic
hisplat_ps_1 <- 
  sum(poststrat_df$n[poststrat_df$HISP == 1]) / sum(poststrat_df$n)
hisplat_ps_0 <- 
  sum(poststrat_df$n[poststrat_df$HISP ==0 ]) / sum(poststrat_df$n)
hisplat_df_1 <- 
  sum(ds_weight$hisplat == 1) / nrow(ds_weight)
hisplat_df_0 <- 
  sum(ds_weight$hisplat == 0) / nrow(ds_weight)

ggplot() + 
  geom_bar(
    aes(x = "1", y = hisplat_ps_1), 
    fill = "red", size = 3, stat= "identity",
    position = position_nudge(x= .1), width = .2
  ) + 
  geom_bar(
    aes(x = "2", y = hisplat_ps_0), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x= .1), width = .2
  ) + 
  geom_bar(
    aes(x = "1", y = hisplat_df_1), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.1), width = .2
  ) + 
  geom_bar(
    aes(x = "2", y = hisplat_df_0), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.1), width = .2
  ) + 
  geom_text(
    aes(x = "1", y = hisplat_ps_1), 
    label = paste0(round(hisplat_ps_1, 2)), 
    position = position_nudge(x = .1, y = .03)
  ) + 
  geom_text(
    aes(x = "2", y = hisplat_ps_0), 
    label = paste0(round(hisplat_ps_0, 2)), 
    position = position_nudge(x = .1, y = .03)
  ) + 
  geom_text(
    aes(x = "1", y = hisplat_df_1), 
    label = paste0(round(hisplat_df_1, 2)), 
    position = position_nudge(x = -.1, y = .03)
  ) + 
  geom_text(
    aes(x = "2", y = hisplat_df_0), 
    label = paste0(round(hisplat_df_0, 2)), 
    position = position_nudge(x = -.1, y = .03)
  ) + 
  scale_x_discrete(labels = c("Hispanic", "Not Hispanic")) + 
  scale_y_continuous(limits = c(0, 1)) + 
  labs(x = "", y = "proportion")

#### White Hispanic
whisplat_ps_1 <- 
  sum(poststrat_df$n[poststrat_df$HISP == 1 & poststrat_df$RACWHT == 1]) /
  sum(poststrat_df$n[poststrat_df$HISP == 1])
whisplat_ps_0 <- 
  sum(poststrat_df$n[poststrat_df$HISP == 1 & poststrat_df$RACWHT == 0]) /
  sum(poststrat_df$n[poststrat_df$HISP == 1])
whisplat_df_1 <- 
  sum(ds_weight$hisplat[ds_weight$white == 1]) /
  nrow(filter(ds_weight, hisplat == 1))
whisplat_df_0 <- 
  sum(ds_weight$hisplat[ds_weight$white == 0]) /
  nrow(filter(ds_weight, hisplat == 1))

ggplot() + 
  geom_bar(
    aes(x = "1", y = whisplat_ps_1), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x= .1), width = .2
  ) + 
  geom_bar(
    aes(x = "2", y = whisplat_ps_0), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x= .1), width = .2
  ) + 
  geom_bar(
    aes(x = "1", y = whisplat_df_1), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.1), width = .2
  ) + 
  geom_bar(
    aes(x = "2", y = whisplat_df_0), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.1), width = .2
  ) + 
  geom_text(
    aes(x = "1", y = whisplat_ps_1), 
    label = paste0(round(whisplat_ps_1, 2)), 
    position = position_nudge(x = .1, y = .03)
  ) + 
  geom_text(
    aes(x = "2", y = whisplat_ps_0), 
    label = paste0(round(whisplat_ps_0, 2)), 
    position = position_nudge(x = .1, y = .03)
  ) + 
  geom_text(
    aes(x = "1", y = whisplat_df_1), 
    label = paste0(round(whisplat_df_1, 2)), 
    position = position_nudge(x = -.1, y = .03)
  ) + 
  geom_text(
    aes(x = "2", y = whisplat_df_0), 
    label = paste0(round(whisplat_df_0, 2)), 
    position = position_nudge(x = -.1, y = .03)
  ) + 
  scale_x_discrete(labels = c("White Hispanic", "Non-white Hispanic")) + 
  scale_y_continuous(limits = c(0, 1)) + 
  labs(x = "", y = "proportion")

#### Age
age_ps_1 <- sum(poststrat_df$n[poststrat_df$age1824 == 1]) / sum(poststrat_df$n)
age_ps_2 <- sum(poststrat_df$n[poststrat_df$age2534 == 1]) / sum(poststrat_df$n)
age_ps_3 <- sum(poststrat_df$n[poststrat_df$age3544 == 1]) / sum(poststrat_df$n)
age_ps_4 <- sum(poststrat_df$n[poststrat_df$age4554 == 1]) / sum(poststrat_df$n)
age_ps_5 <- sum(poststrat_df$n[poststrat_df$age5564 == 1]) / sum(poststrat_df$n)
age_ps_6 <- sum(poststrat_df$n[poststrat_df$age6599 == 1]) / sum(poststrat_df$n)
age_df_1 <- sum(ds_weight$age1824 == 1) / nrow(ds_weight)
age_df_2 <- sum(ds_weight$age2534 == 1) / nrow(ds_weight)
age_df_3 <- sum(ds_weight$age3544 == 1) / nrow(ds_weight)
age_df_4 <- sum(ds_weight$age4554 == 1) / nrow(ds_weight)
age_df_5 <- sum(ds_weight$age5564 == 1) / nrow(ds_weight)
age_df_6 <- sum(ds_weight$age6599 == 1) / nrow(ds_weight)

ggplot() + 
  geom_bar(
    aes(x = "1", y = age_df_1), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.175), width = .35
  ) + 
  geom_bar(
    aes(x = "2", y = age_df_2), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.175), width = .35
  ) + 
  geom_bar(
    aes(x = "3", y = age_df_3), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.175), width = .35
  ) + 
  geom_bar(
    aes(x = "4", y = age_df_4), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.175), width = .35
  ) +
  geom_bar(
    aes(x = "5", y = age_df_5), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.175), width = .35
  ) + 
  geom_bar(
    aes(x = "6", y = age_df_6), 
    fill = "black", size = 3, stat= "identity", 
    position = position_nudge(x= -.175), width = .35
  ) +
  geom_bar(
    aes(x = "1", y = age_ps_1), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x = .175), width = .35
  ) + 
  geom_bar(
    aes(x = "2", y = age_ps_2), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x = .175), width = .35
  ) + 
  geom_bar(
    aes(x = "3", y = age_ps_3), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x = .175), width = .35
  ) + 
  geom_bar(
    aes(x = "4", y = age_ps_4), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x = .175), width = .35
  ) + 
  geom_bar(
    aes(x = "5", y = age_ps_5), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x = .175), width = .35
  ) + 
  geom_bar(
    aes(x = "6", y = age_ps_6), 
    fill = "red", size = 3, stat= "identity", 
    position = position_nudge(x = .175), width = .35
  ) + 
  geom_text(
    aes(x = "1", y = age_ps_1), 
    label = paste0(round(age_ps_1, 2)), 
    position = position_nudge(x = .2, y = .03), size = 3
  ) + 
  geom_text(
    aes(x = "2", y = age_ps_2), 
    label = paste0(round(age_ps_2, 2)), 
    position = position_nudge(x = .2, y = .03), size = 3
  ) + 
  geom_text(
    aes(x = "3", y = age_ps_3), 
    label = paste0(round(age_ps_3, 2)), 
    position = position_nudge(x = .2, y = .03), size = 3
  ) + 
  geom_text(
    aes(x = "4", y = age_ps_4), 
    label = paste0(round(age_ps_4, 2)), 
    position = position_nudge(x = .2, y = .03), size = 3
  ) + 
  geom_text(
    aes(x = "5", y = age_ps_5), 
    label = paste0(round(age_ps_5, 2)), 
    position = position_nudge(x = .2, y = .03), size = 3
  ) + 
  geom_text(
    aes(x = "6", y = age_ps_6), 
    label = paste0(round(age_ps_6, 2)), 
    position = position_nudge(x = .2, y = .03), size = 3
  ) + 
  geom_text(
    aes(x = "1", y = age_df_1), 
    label = paste0(round(age_df_1, 2)), 
    position = position_nudge(x = -.2, y = .03), size = 3
  ) + 
  geom_text(
    aes(x = "2", y = age_df_2), 
    label = paste0(round(age_df_2, 2)), 
    position = position_nudge(x = -.2, y = .03), size = 3
  ) + 
  geom_text(
    aes(x = "3", y = age_df_3), 
    label = paste0(round(age_df_3, 2)), 
    position = position_nudge(x = -.2, y = .03), size = 3
  ) + 
  geom_text(
    aes(x = "4", y = age_df_4), 
    label = paste0(round(age_df_4, 2)), 
    position = position_nudge(x = -.2, y = .03), size = 3
  ) + 
  geom_text(
    aes(x = "5", y = age_df_5), 
    label = paste0(round(age_df_5, 2)), 
    position = position_nudge(x = -.2, y = .03), size = 3
  ) + 
  geom_text(
    aes(x = "6", y = age_df_6), 
    label = paste0(round(age_df_6, 2)), 
    position = position_nudge(x = -.2, y = .03), size = 3
  ) + 
  scale_x_discrete(labels = c("18-24", "25-34", "35-44", "45-54", "55-64", "65-99")) + 
  scale_y_continuous(limits = c(0, 1)) + 
  labs(x = "", y = "proportion")

### Table A23: Population Average Treatment Effects on MC Effectiveness ----
summary(
  lm(
    effective ~ 
      pos_treatment_ref + partymatch + partyr2 + 
      white + black + hisplat + asam + natam + rother + 
      poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
    data = ds_weight, 
    weights = weightR
  )
)

summary(
  lm(
    effective ~ 
      pos_treatment_ref + partymatch + partyr2 + 
      white + black + hisplat + asam + natam + rother + 
      poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
    data = ds_weight, 
    weights = weightEB
  )
)

summary(
  lm(
    money ~ 
      pos_treatment_ref + partymatch + partyr2 + 
      white + black + hisplat + asam + natam + rother + 
      poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
    data = ds_weight, 
    weights = weightR
  )
)

summary(
  lm(
    money ~ 
      pos_treatment_ref + partymatch + partyr2 + 
      white + black + hisplat + asam + natam + rother + 
      poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
    data = ds_weight, 
    weights = weightEB
  )
)

### Table A24: Population Average Treatment Effects on MC Support ----
summary(
  lm(
    therm ~ 
      pos_treatment_ref + partymatch + partyr2 + 
      white + black + hisplat + asam + natam + rother + 
      poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
    data = ds_weight, 
    weights = weightR
  )
)

summary(
  lm(
    therm ~ 
      pos_treatment_ref + partymatch + partyr2 + 
      white + black + hisplat + asam + natam + rother + 
      poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
    data = ds_weight, 
    weights = weightEB
  )
)

summary(
  lm(
    pleased ~ 
      pos_treatment_ref + partymatch + partyr2 + 
      white + black + hisplat + asam + natam + rother + 
      poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
    data = ds_weight, 
    weights = weightR
  )
)

summary(
  lm(
    pleased ~ 
      pos_treatment_ref + partymatch + partyr2 + 
      white + black + hisplat + asam + natam + rother + 
      poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
    data = ds_weight, 
    weights = weightEB
  )
)

### Figure A8: Survey Weight Distributions ----
ggplot(ds_weight) + 
  geom_histogram(aes(weightEB), boundary = 0, binwidth = 0.01) + 
  scale_x_log10()

ggplot(ds_weight) + 
  geom_histogram(aes(weightR), boundary = 0, binwidth = 0.05)

## 6.3 Checking for Interactive Effects of Treatment and Race ----
### Figure A9: Conditional Average Treatment Effects by Race ----
summary(
  effectiveOG <- 
    lm(
      effective ~ 
        pos_treatment_ref + partymatch + partyr2 + 
        white + black + hisplat + asam + natam + rother + 
        poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
      data = ds
    )
)

summary(
  moneyOG <- 
    lm(
      money ~ 
        pos_treatment_ref + partymatch + partyr2 + 
        white + black + hisplat + asam + natam + rother + 
        poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
      data = ds
    )
)

summary(
  thermOG <- 
    lm(
      therm ~ 
        pos_treatment_ref + partymatch + partyr2 + 
        white + black + hisplat + asam + natam + rother + 
        poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
      data = ds
    )
)

summary(
  pleasedOG <- 
    lm(
      pleased ~ 
        pos_treatment_ref + partymatch + partyr2 + 
        white + black + hisplat + asam + natam + rother + 
        poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
      data = ds
    )
)

summary(
  effectiveTXR <- 
    lm(
      effective ~ 
        pos_treatment_ref * 
        (white + black + hisplat + asam + natam + rother) + 
        partymatch + partyr2 + poly(age, 2, raw = TRUE) +
        gender + edu + ideo + income, 
      data = ds
    )
)

summary(
  moneyTXR <- 
    lm(
      money ~ 
        pos_treatment_ref * 
        (white + black + hisplat + asam + natam + rother) + 
        partymatch + partyr2 + poly(age, 2, raw = TRUE) + 
        gender + edu + ideo + income, 
      data = ds
    )
)

summary(
  thermTXR <- 
    lm(
      therm ~ 
        pos_treatment_ref * 
        (white + black + hisplat + asam + natam + rother) + 
        partymatch + partyr2 + poly(age, 2, raw = TRUE) + 
        gender + edu + ideo + income, 
      data = ds
    )
)

summary(
  pleasedTXR <- 
    lm(
      pleased ~ 
        pos_treatment_ref * 
        (white + black + hisplat + asam + natam + rother) + 
        partymatch + partyr2 + poly(age, 2, raw = TRUE) + 
        gender + edu + ideo + income, 
      data = ds
    )
)

target <- 
  data.frame(
    pos_treatment_ref = c(rep("nocom", 6), rep("commem", 6), rep("comlead", 6)), 
    partyr2 = rep("rep", 18),
    white =   rep(c(rep(1, 1), rep(0, 5)), 3), 
    black =   rep(c(rep(0, 1), rep(1, 1), rep(0, 4)), 3), 
    hisplat = rep(c(rep(0, 2), rep(1, 1), rep(0, 3)), 3), 
    asam =    rep(c(rep(0, 3), rep(1, 1), rep(0, 2)), 3), 
    natam =   rep(c(rep(0, 4), rep(1, 1), rep(0, 1)), 3), 
    rother =  rep(c(rep(0, 5), rep(1, 1)), 3), 
    partymatch = rep("1", 18), 
    age = rep(45, 18), 
    gender = rep("male", 18), 
    edu = rep("Less_than_Bachelors", 18), 
    ideo = rep(3, 18), 
    income = rep(5, 18)
  )

Rpredeff <- predict(
  effectiveTXR, target, interval = "confidence", se.fit = TRUE
)

Rpredmoney <- predict(
  moneyTXR, target, interval = "confidence", se.fit = TRUE
)

Rpredtherm <- predict(
  thermTXR, target, interval = "confidence", se.fit = TRUE
)

Rpredpleased <- predict(
  pleasedTXR, target, interval = "confidence", se.fit = TRUE
)

Rpredeff$treat <- Rpredmoney$treat <- Rpredtherm$treat <- Rpredpleased$treat <- 
  c(rep("nocom", 6), rep("commem", 6), rep("comlead", 6))

Rpredeff$race <- Rpredmoney$race <- Rpredtherm$race <- Rpredpleased$race <- 
  rep(c("white", "black", "hisplat", "asam", "natam", "rother"), 3)

Rpredeff <- data.frame(Rpredeff)
Rpredmoney <- data.frame(Rpredmoney)
Rpredtherm <- data.frame(Rpredtherm)
Rpredpleased <- data.frame(Rpredpleased)

race_effects <- 
  data.frame(
    dv = 
      c(
        rep("Passing Legislation (1-7)", 12), 
        rep("Securing Funding (1-7)", 12), 
        rep("Thermometer (0-100)", 12), 
        rep("Pleased Rating (1-7)", 12)
      ),
    treat = rep(
      c(
        rep("Subcom.\nMember", 6), 
        rep("Subcom.\nLeader", 6)
        ), 
      4
    ), 
    race =
      rep(
        c(
          rep(
            c(
              "White", "Black", "Hispanic/Latino", 
              "Asian American", "Native American", "Other"
            ),
            2
          )
        ), 
        4
    ),
    est =
      c(
        Rpredeff$fit.fit[Rpredeff$treat == "commem" & Rpredeff$race == "white"] - 
          Rpredeff$fit.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "white"], 
        Rpredeff$fit.fit[Rpredeff$treat == "commem" & Rpredeff$race == "black"] - 
          Rpredeff$fit.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "black"], 
        Rpredeff$fit.fit[Rpredeff$treat == "commem" & Rpredeff$race == "hisplat"] - 
          Rpredeff$fit.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "hisplat"], 
        Rpredeff$fit.fit[Rpredeff$treat == "commem" & Rpredeff$race == "asam"] - 
          Rpredeff$fit.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "asam"], 
        Rpredeff$fit.fit[Rpredeff$treat == "commem" & Rpredeff$race == "natam"] - 
          Rpredeff$fit.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "natam"], 
        Rpredeff$fit.fit[Rpredeff$treat == "commem" & Rpredeff$race == "rother"] - 
          Rpredeff$fit.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "rother"], 
        Rpredeff$fit.fit[Rpredeff$treat == "comlead" & Rpredeff$race == "white"] - 
          Rpredeff$fit.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "white"], 
        Rpredeff$fit.fit[Rpredeff$treat == "comlead" & Rpredeff$race == "black"] - 
          Rpredeff$fit.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "black"], 
        Rpredeff$fit.fit[Rpredeff$treat == "comlead" & Rpredeff$race == "hisplat"] - 
          Rpredeff$fit.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "hisplat"], 
        Rpredeff$fit.fit[Rpredeff$treat == "comlead" & Rpredeff$race == "asam"] - 
          Rpredeff$fit.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "asam"], 
        Rpredeff$fit.fit[Rpredeff$treat == "comlead" & Rpredeff$race == "natam"] - 
          Rpredeff$fit.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "natam"], 
        Rpredeff$fit.fit[Rpredeff$treat == "comlead" & Rpredeff$race == "rother"] - 
          Rpredeff$fit.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "rother"],
        Rpredmoney$fit.fit[Rpredmoney$treat == "commem" & Rpredmoney$race == "white"] - 
          Rpredmoney$fit.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "white"], 
        Rpredmoney$fit.fit[Rpredmoney$treat == "commem" & Rpredmoney$race == "black"] - 
          Rpredmoney$fit.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "black"], 
        Rpredmoney$fit.fit[Rpredmoney$treat == "commem" & Rpredmoney$race == "hisplat"] - 
          Rpredmoney$fit.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "hisplat"], 
        Rpredmoney$fit.fit[Rpredmoney$treat == "commem" & Rpredmoney$race == "asam"] - 
          Rpredmoney$fit.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "asam"], 
        Rpredmoney$fit.fit[Rpredmoney$treat == "commem" & Rpredmoney$race == "natam"] - 
          Rpredmoney$fit.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "natam"], 
        Rpredmoney$fit.fit[Rpredmoney$treat == "commem" & Rpredmoney$race == "rother"] - 
          Rpredmoney$fit.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "rother"], 
        Rpredmoney$fit.fit[Rpredmoney$treat == "comlead" & Rpredmoney$race == "white"] - 
          Rpredmoney$fit.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "white"], 
        Rpredmoney$fit.fit[Rpredmoney$treat == "comlead" & Rpredmoney$race == "black"] - 
          Rpredmoney$fit.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "black"], 
        Rpredmoney$fit.fit[Rpredmoney$treat == "comlead" & Rpredmoney$race == "hisplat"] - 
          Rpredmoney$fit.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "hisplat"], 
        Rpredmoney$fit.fit[Rpredmoney$treat == "comlead" & Rpredmoney$race == "asam"] - 
          Rpredmoney$fit.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "asam"], 
        Rpredmoney$fit.fit[Rpredmoney$treat == "comlead" & Rpredmoney$race == "natam"] - 
          Rpredmoney$fit.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "natam"], 
        Rpredmoney$fit.fit[Rpredmoney$treat == "comlead" & Rpredmoney$race == "rother"] - 
          Rpredmoney$fit.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "rother"],
        Rpredtherm$fit.fit[Rpredtherm$treat == "commem" & Rpredtherm$race == "white"] - 
          Rpredtherm$fit.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "white"], 
        Rpredtherm$fit.fit[Rpredtherm$treat == "commem" & Rpredtherm$race == "black"] - 
          Rpredtherm$fit.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "black"], 
        Rpredtherm$fit.fit[Rpredtherm$treat == "commem" & Rpredtherm$race == "hisplat"] - 
          Rpredtherm$fit.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "hisplat"], 
        Rpredtherm$fit.fit[Rpredtherm$treat == "commem" & Rpredtherm$race == "asam"] - 
          Rpredtherm$fit.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "asam"], 
        Rpredtherm$fit.fit[Rpredtherm$treat == "commem" & Rpredtherm$race == "natam"] - 
          Rpredtherm$fit.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "natam"], 
        Rpredtherm$fit.fit[Rpredtherm$treat == "commem" & Rpredtherm$race == "rother"] - 
          Rpredtherm$fit.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "rother"], 
        Rpredtherm$fit.fit[Rpredtherm$treat == "comlead" & Rpredtherm$race == "white"] - 
          Rpredtherm$fit.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "white"], 
        Rpredtherm$fit.fit[Rpredtherm$treat == "comlead" & Rpredtherm$race == "black"] - 
          Rpredtherm$fit.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "black"], 
        Rpredtherm$fit.fit[Rpredtherm$treat == "comlead" & Rpredtherm$race == "hisplat"] - 
          Rpredtherm$fit.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "hisplat"], 
        Rpredtherm$fit.fit[Rpredtherm$treat == "comlead" & Rpredtherm$race == "asam"] - 
          Rpredtherm$fit.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "asam"], 
        Rpredtherm$fit.fit[Rpredtherm$treat == "comlead" & Rpredtherm$race == "natam"] - 
          Rpredtherm$fit.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "natam"], 
        Rpredtherm$fit.fit[Rpredtherm$treat == "comlead" & Rpredtherm$race == "rother"] - 
          Rpredtherm$fit.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "rother"],
        Rpredpleased$fit.fit[Rpredpleased$treat == "commem" & Rpredpleased$race == "white"] - 
          Rpredpleased$fit.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "white"], 
        Rpredpleased$fit.fit[Rpredpleased$treat == "commem" & Rpredpleased$race == "black"] - 
          Rpredpleased$fit.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "black"], 
        Rpredpleased$fit.fit[Rpredpleased$treat == "commem" & Rpredpleased$race == "hisplat"] - 
          Rpredpleased$fit.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "hisplat"], 
        Rpredpleased$fit.fit[Rpredpleased$treat == "commem" & Rpredpleased$race == "asam"] - 
          Rpredpleased$fit.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "asam"], 
        Rpredpleased$fit.fit[Rpredpleased$treat == "commem" & Rpredpleased$race == "natam"] - 
          Rpredpleased$fit.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "natam"], 
        Rpredpleased$fit.fit[Rpredpleased$treat == "commem" & Rpredpleased$race == "rother"] - 
          Rpredpleased$fit.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "rother"], 
        Rpredpleased$fit.fit[Rpredpleased$treat == "comlead" & Rpredpleased$race == "white"] - 
          Rpredpleased$fit.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "white"], 
        Rpredpleased$fit.fit[Rpredpleased$treat == "comlead" & Rpredpleased$race == "black"] - 
          Rpredpleased$fit.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "black"], 
        Rpredpleased$fit.fit[Rpredpleased$treat == "comlead" & Rpredpleased$race == "hisplat"] - 
          Rpredpleased$fit.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "hisplat"], 
        Rpredpleased$fit.fit[Rpredpleased$treat == "comlead" & Rpredpleased$race == "asam"] - 
          Rpredpleased$fit.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "asam"], 
        Rpredpleased$fit.fit[Rpredpleased$treat == "comlead" & Rpredpleased$race == "natam"] - 
          Rpredpleased$fit.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "natam"], 
        Rpredpleased$fit.fit[Rpredpleased$treat == "comlead" & Rpredpleased$race == "rother"] - 
          Rpredpleased$fit.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "rother"]
      ), 
    se = 
      c(
        sqrt(Rpredeff$se.fit[Rpredeff$treat == "commem" & Rpredeff$race == "white"]^2 + 
               Rpredeff$se.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "white"]^2),
        sqrt(Rpredeff$se.fit[Rpredeff$treat == "commem" & Rpredeff$race == "black"]^2 + 
               Rpredeff$se.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "black"]^2),
        sqrt(Rpredeff$se.fit[Rpredeff$treat == "commem" & Rpredeff$race == "hisplat"]^2 + 
               Rpredeff$se.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "hisplat"]^2), 
        sqrt(Rpredeff$se.fit[Rpredeff$treat == "commem" & Rpredeff$race == "asam"]^2 + 
               Rpredeff$se.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "asam"]^2),
        sqrt(Rpredeff$se.fit[Rpredeff$treat == "commem" & Rpredeff$race == "natam"]^2 + 
               Rpredeff$se.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "natam"]^2),
        sqrt(Rpredeff$se.fit[Rpredeff$treat == "commem" & Rpredeff$race == "rother"]^2 + 
               Rpredeff$se.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "rother"]^2),
        sqrt(Rpredeff$se.fit[Rpredeff$treat == "comlead" & Rpredeff$race == "white"]^2 + 
               Rpredeff$se.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "white"]^2),
        sqrt(Rpredeff$se.fit[Rpredeff$treat == "comlead" & Rpredeff$race == "black"]^2 + 
               Rpredeff$se.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "black"]^2),
        sqrt(Rpredeff$se.fit[Rpredeff$treat == "comlead" & Rpredeff$race == "hisplat"]^2 + 
               Rpredeff$se.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "hisplat"]^2), 
        sqrt(Rpredeff$se.fit[Rpredeff$treat == "comlead" & Rpredeff$race == "asam"]^2 + 
               Rpredeff$se.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "asam"]^2),
        sqrt(Rpredeff$se.fit[Rpredeff$treat == "comlead" & Rpredeff$race == "natam"]^2 + 
               Rpredeff$se.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "natam"]^2),
        sqrt(Rpredeff$se.fit[Rpredeff$treat == "comlead" & Rpredeff$race == "rother"]^2 + 
               Rpredeff$se.fit[Rpredeff$treat == "nocom" & Rpredeff$race == "rother"]^2), 
        sqrt(Rpredmoney$se.fit[Rpredmoney$treat == "commem" & Rpredmoney$race == "white"]^2 + 
               Rpredmoney$se.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "white"]^2),
        sqrt(Rpredmoney$se.fit[Rpredmoney$treat == "commem" & Rpredmoney$race == "black"]^2 + 
               Rpredmoney$se.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "black"]^2),
        sqrt(Rpredmoney$se.fit[Rpredmoney$treat == "commem" & Rpredmoney$race == "hisplat"]^2 + 
               Rpredmoney$se.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "hisplat"]^2), 
        sqrt(Rpredmoney$se.fit[Rpredmoney$treat == "commem" & Rpredmoney$race == "asam"]^2 + 
               Rpredmoney$se.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "asam"]^2),
        sqrt(Rpredmoney$se.fit[Rpredmoney$treat == "commem" & Rpredmoney$race == "natam"]^2 + 
               Rpredmoney$se.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "natam"]^2),
        sqrt(Rpredmoney$se.fit[Rpredmoney$treat == "commem" & Rpredmoney$race == "rother"]^2 + 
               Rpredmoney$se.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "rother"]^2),
        sqrt(Rpredmoney$se.fit[Rpredmoney$treat == "comlead" & Rpredmoney$race == "white"]^2 + 
               Rpredmoney$se.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "white"]^2),
        sqrt(Rpredmoney$se.fit[Rpredmoney$treat == "comlead" & Rpredmoney$race == "black"]^2 + 
               Rpredmoney$se.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "black"]^2),
        sqrt(Rpredmoney$se.fit[Rpredmoney$treat == "comlead" & Rpredmoney$race == "hisplat"]^2 + 
               Rpredmoney$se.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "hisplat"]^2), 
        sqrt(Rpredmoney$se.fit[Rpredmoney$treat == "comlead" & Rpredmoney$race == "asam"]^2 + 
               Rpredmoney$se.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "asam"]^2),
        sqrt(Rpredmoney$se.fit[Rpredmoney$treat == "comlead" & Rpredmoney$race == "natam"]^2 + 
               Rpredmoney$se.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "natam"]^2),
        sqrt(Rpredmoney$se.fit[Rpredmoney$treat == "comlead" & Rpredmoney$race == "rother"]^2 + 
               Rpredmoney$se.fit[Rpredmoney$treat == "nocom" & Rpredmoney$race == "rother"]^2),
        sqrt(Rpredtherm$se.fit[Rpredtherm$treat == "commem" & Rpredtherm$race == "white"]^2 + 
               Rpredtherm$se.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "white"]^2),
        sqrt(Rpredtherm$se.fit[Rpredtherm$treat == "commem" & Rpredtherm$race == "black"]^2 + 
               Rpredtherm$se.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "black"]^2),
        sqrt(Rpredtherm$se.fit[Rpredtherm$treat == "commem" & Rpredtherm$race == "hisplat"]^2 + 
               Rpredtherm$se.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "hisplat"]^2), 
        sqrt(Rpredtherm$se.fit[Rpredtherm$treat == "commem" & Rpredtherm$race == "asam"]^2 + 
               Rpredtherm$se.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "asam"]^2),
        sqrt(Rpredtherm$se.fit[Rpredtherm$treat == "commem" & Rpredtherm$race == "natam"]^2 + 
               Rpredtherm$se.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "natam"]^2),
        sqrt(Rpredtherm$se.fit[Rpredtherm$treat == "commem" & Rpredtherm$race == "rother"]^2 + 
               Rpredtherm$se.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "rother"]^2),
        sqrt(Rpredtherm$se.fit[Rpredtherm$treat == "comlead" & Rpredtherm$race == "white"]^2 + 
               Rpredtherm$se.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "white"]^2),
        sqrt(Rpredtherm$se.fit[Rpredtherm$treat == "comlead" & Rpredtherm$race == "black"]^2 + 
               Rpredtherm$se.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "black"]^2),
        sqrt(Rpredtherm$se.fit[Rpredtherm$treat == "comlead" & Rpredtherm$race == "hisplat"]^2 + 
               Rpredtherm$se.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "hisplat"]^2), 
        sqrt(Rpredtherm$se.fit[Rpredtherm$treat == "comlead" & Rpredtherm$race == "asam"]^2 + 
               Rpredtherm$se.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "asam"]^2),
        sqrt(Rpredtherm$se.fit[Rpredtherm$treat == "comlead" & Rpredtherm$race == "natam"]^2 +
               Rpredtherm$se.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "natam"]^2),
        sqrt(Rpredtherm$se.fit[Rpredtherm$treat == "comlead" & Rpredtherm$race == "rother"]^2 + 
               Rpredtherm$se.fit[Rpredtherm$treat == "nocom" & Rpredtherm$race == "rother"]^2),
        sqrt(Rpredpleased$se.fit[Rpredpleased$treat == "commem" & Rpredpleased$race == "white"]^2 + 
               Rpredpleased$se.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "white"]^2),
        sqrt(Rpredpleased$se.fit[Rpredpleased$treat == "commem" & Rpredpleased$race == "black"]^2 + 
               Rpredpleased$se.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "black"]^2),
        sqrt(Rpredpleased$se.fit[Rpredpleased$treat == "commem" & Rpredpleased$race == "hisplat"]^2 + 
               Rpredpleased$se.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "hisplat"]^2), 
        sqrt(Rpredpleased$se.fit[Rpredpleased$treat == "commem" & Rpredpleased$race == "asam"]^2 + 
               Rpredpleased$se.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "asam"]^2),
        sqrt(Rpredpleased$se.fit[Rpredpleased$treat == "commem" & Rpredpleased$race == "natam"]^2 + 
               Rpredpleased$se.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "natam"]^2),
        sqrt(Rpredpleased$se.fit[Rpredpleased$treat == "commem" & Rpredpleased$race == "rother"]^2 + 
               Rpredpleased$se.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "rother"]^2),
        sqrt(Rpredpleased$se.fit[Rpredpleased$treat == "comlead" & Rpredpleased$race == "white"]^2 + 
               Rpredpleased$se.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "white"]^2),
        sqrt(Rpredpleased$se.fit[Rpredpleased$treat == "comlead" & Rpredpleased$race == "black"]^2 + 
               Rpredpleased$se.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "black"]^2),
        sqrt(Rpredpleased$se.fit[Rpredpleased$treat == "comlead" & Rpredpleased$race == "hisplat"]^2 + 
               Rpredpleased$se.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "hisplat"]^2), 
        sqrt(Rpredpleased$se.fit[Rpredpleased$treat == "comlead" & Rpredpleased$race == "asam"]^2 + 
               Rpredpleased$se.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "asam"]^2),
        sqrt(Rpredpleased$se.fit[Rpredpleased$treat == "comlead" & Rpredpleased$race == "natam"]^2 + 
               Rpredpleased$se.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "natam"]^2),
        sqrt(Rpredpleased$se.fit[Rpredpleased$treat == "comlead" & Rpredpleased$race == "rother"]^2 + 
               Rpredpleased$se.fit[Rpredpleased$treat == "nocom" & Rpredpleased$race == "rother"]^2)
      )
  )



race_effects %>%
  mutate(
    lb = est - 1.96 * se, ub = est + 1.96 * se, 
    race = factor(
      race, 
      levels = c(
        "White", "Black", "Hispanic/Latino", 
        "Asian American", "Native American", "Other"
      )
    ), 
    dv = factor(
      dv, 
      levels = c(
        "Passing Legislation (1-7)", 
        "Securing Funding (1-7)", 
        "Thermometer (0-100)", 
        "Pleased Rating (1-7)"
      )
    )
  ) %>%
  ggplot(
    ., 
    aes(
      x = treat, 
      y = est, 
      group = race, 
      color = race, 
      shape = race
    )
  ) +
  geom_hline(yintercept = 0, color = "grey30", alpha = .4) + 
  geom_point(
    position = position_dodge(width = -.5), 
    size = 3
  ) + 
  scale_x_discrete(position = "top") +
  facet_wrap(dv ~ ., ncol = 1, scales = "free_x", strip.position = "left") + 
  geom_errorbar(
    aes(
      ymin = lb, 
      ymax = ub
    ), 
    width = 0, 
    position = position_dodge(width = -.5)
  ) + 
  ggh4x::facetted_pos_scales(
    y = list(
      scale_y_continuous(limits = c(-5, 5), breaks = seq(-5, 5, 5)),
      scale_y_continuous(limits = c(-5, 5), breaks = seq(-5, 5, 5)),
      scale_y_continuous(limits = c(-60, 60), breaks = seq(-50, 50, 50)),
      scale_y_continuous(limits = c(-5, 5), breaks = seq(-5, 5, 5))
    )
  ) +
  coord_flip() +
  labs(
    color = "", 
    shape = "", 
    group = "", 
    x = "", 
    y = "Conditional Average Treatment Effect"
  )

## 6.4 Checking for Interactive Effects of Respondent Party and MC Party ----
### Table A25: Average Treatment Effects with Interaction (Effectiveness) ----
summary(
  eff_mod5 <- 
    lm(
      effective ~ 
        pos_treatment_ref + par_treatment * partyr2 + 
        white + black + hisplat + asam + natam + rother + 
        poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
      data = ds
    )
)

summary(eff_mod6 <- lm(effective ~ partymatch + partyr2, data = ds))
summary(eff_mod7 <- lm(effective ~ par_treatment * partyr2, data = ds))

summary(
  money_mod5 <- 
    lm(
      money ~ 
        pos_treatment_ref + par_treatment * partyr2 + 
        white + black + hisplat + asam + natam + rother + 
        poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
      data = ds
    )
)

summary(money_mod6 <- lm(money ~ partymatch + partyr2, data = ds))
summary(money_mod7 <- lm(money ~ par_treatment * partyr2, data = ds))

### Table A26: Average Treatment Effects with Interaction (Support) ----
summary(
  therm_mod5 <- 
    lm(
      therm ~ 
        pos_treatment_ref + par_treatment * partyr2 + 
        white + black + hisplat + asam + natam + rother + 
        poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
      data = ds
    )
)

summary(therm_mod6 <- lm(therm ~ partymatch + partyr2, data = ds))
summary(therm_mod7 <- lm(therm ~ par_treatment * partyr2, data = ds))

summary(
  pleased_mod5 <- 
    lm(
      pleased ~ 
        pos_treatment_ref + par_treatment * partyr2 + 
        white + black + hisplat + asam + natam + rother + 
        poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
      data = ds
    )
)

summary(pleased_mod6 <- lm(pleased ~ partymatch + partyr2, data = ds))
summary(pleased_mod7 <- lm(pleased ~ par_treatment * partyr2, data = ds))

### Figure A10: Predicted Outcomes (Partisan Match) ----
new_df1 <- 
  data.frame(
    partymatch = rep(c("0", "1"), 2), 
    partyr2 = c(rep("dem", 2), rep("rep", 2))
  )

pred1_eff <- predict(
  eff_mod6, new_df1, interval = "confidence", se.fit = TRUE
)

pred1_money <- predict(
  money_mod6, new_df1, interval = "confidence", se.fit = TRUE
)

pred1_therm <- predict(
  therm_mod6, new_df1, interval = "confidence", se.fit = TRUE
)

pred1_pleased <- predict(
  pleased_mod6, new_df1, interval = "confidence", se.fit = TRUE
)

pred_eff1 <- cbind(new_df1, pred1_eff$fit)
pred_money1 <- cbind(new_df1, pred1_money$fit)
pred_therm1 <- cbind(new_df1, pred1_therm$fit)
pred_pleased1 <- cbind(new_df1, pred1_pleased$fit)

pred_eff1$se <- pred1_eff$se.fit
pred_money1$se <- pred1_money$se.fit
pred_therm1$se <- pred1_therm$se.fit
pred_pleased1$se <- pred1_pleased$se.fit

pred_eff1$dv <- "Effectiveness"
pred_money1$dv <- "Money"
pred_therm1$dv <- "Thermometer"
pred_pleased1$dv <- "Pleased"

pred_eff1$model <- "Party Match"
pred_money1$model <- "Party Match"
pred_therm1$model <- "Party Match"
pred_pleased1$model <- "Party Match"

pred_df1 <- rbind(pred_eff1, pred_money1, pred_therm1, pred_pleased1)

pred_eff1 %>% 
  mutate(
    partyr2 = case_when(
      partyr2 == "dem" ~ "Democrats", 
      partyr2 == "rep" ~ "Republicans"
    )
  ) %>%
  ggplot(
    ., 
    aes(
      x = partymatch, 
      y = fit, 
      ymin = lwr, 
      ymax = upr, 
      color = partyr2, 
      shape = partyr2, 
      group = partyr2
    )
  ) + 
  geom_pointrange( 
    size = 1, 
    linewidth = 1, alpha = .5
  ) +
  geom_line(linewidth = 1, show.legend = F, alpha = .5) +
  scale_y_continuous(limits = c(4, 5.5)) + 
  scale_color_manual(values = c("blue", "red")) + 
  annotate(
    "text", 
    x = .85, 
    y = pred_eff1[1, 3], 
    label = paste0(round(pred_eff1[1, 3], 3)),
    color = "blue"
  ) +
  annotate(
    "text", 
    x = .85, 
    y = pred_eff1[3, 3], 
    label = paste0(round(pred_eff1[3, 3], 3)), 
    color = "red"
  ) +
  annotate(
    "text", 
    x = 2.15, 
    y = pred_eff1[2, 3], 
    label = paste0(round(pred_eff1[2, 3], 3)), 
    color = "blue"
  ) +
  annotate(
    "text", 
    x = 2.15, 
    y = pred_eff1[4, 3], 
    label = paste0(round(pred_eff1[4, 3], 3)), 
    color = "red"
  ) +
  annotate(
    "text", 
    x = 1.5, 
    y = .5 * (pred_eff1[2, 3] + pred_eff1[1, 3]), 
    label = paste0("+", round((pred_eff1[2, 3] - pred_eff1[1, 3]), 3)), 
    color = "blue", 
    vjust = -1, 
    fontface = 2
  ) +
  annotate(
    "text", 
    x = 1.5, 
    y = .5 * (pred_eff1[4, 3] + pred_eff1[3, 3]), 
    label = paste0("+", round((pred_eff1[4, 3] - pred_eff1[3, 3]), 3)), 
    color = "red", 
    vjust = 2, 
    fontface = 2
  ) +
  labs(
    x = "", 
    title = "DV: Effectiveness", 
    color = "Respondent\nParty", 
    shape = "Respondent\nParty"
  )

pred_money1 %>% 
  mutate(
    partyr2 = case_when(
      partyr2 == "dem" ~ "Democrats", 
      partyr2 == "rep" ~ "Republicans"
    )
  ) %>%
  ggplot(
    ., 
    aes(
      x = partymatch, 
      y = fit, 
      ymin = lwr, 
      ymax = upr,  
      color = partyr2, 
      shape = partyr2, 
      group = partyr2
    )
  ) + 
  geom_pointrange(
    size = 1, 
    linewidth = 1, alpha = .5
  ) +
  geom_line(linewidth = 1, show.legend = F, alpha = .5) +
  scale_y_continuous(limits = c(4, 5.5)) + 
  scale_color_manual(values = c("blue", "red")) + 
  annotate(
    "text", 
    x = .85, 
    y = pred_money1[1, 3], 
    label = paste0(round(pred_money1[1, 3], 3)), 
    color = "blue"
  ) +
  annotate(
    "text", 
    x = .85, 
    y = pred_money1[3, 3], 
    label = paste0(round(pred_money1[3, 3], 3)), 
    color = "red"
  ) +
  annotate(
    "text", 
    x = 2.15, 
    y = pred_money1[2, 3], 
    label = paste0(round(pred_money1[2, 3], 3)), 
    color = "blue"
  ) +
  annotate(
    "text", 
    x = 2.15, 
    y = pred_money1[4, 3], 
    label = paste0(round(pred_money1[4, 3], 3)), 
    color = "red"
  ) +
  annotate(
    "text", 
    x = 1.5, 
    y = .5 * (pred_money1[2, 3] + pred_money1[1, 3]), 
    label = paste0("+", round((pred_money1[2, 3] - pred_money1[1, 3]), 3)), 
    color = "blue", 
    vjust = -1, 
    fontface = 2
  ) +
  annotate(
    "text", 
    x = 1.5, 
    y = .5 * (pred_money1[4, 3] + pred_money1[3, 3]), 
    label = paste0("+", round((pred_money1[4, 3] - pred_money1[3, 3]), 3)), 
    color = "red", 
    vjust = 2, 
    fontface = 2
  ) +
  labs(
    x = "", 
    title = "DV: Money", 
    color = "Respondent\nParty", 
    shape = "Respondent\nParty"
  )

pred_therm1 %>% 
  mutate(
    partyr2 = case_when(
      partyr2 == "dem" ~ "Democrats", 
      partyr2 == "rep" ~ "Republicans"
    )
  ) %>%
  ggplot(
    ., 
    aes(
      x = partymatch, 
      y = fit, 
      ymin = lwr, 
      ymax = upr, 
      color = partyr2, 
      group = partyr2, 
      shape = partyr2, 
      group = partyr2
    )
  ) + 
  geom_pointrange(
    size = 1, 
    linewidth = 1, alpha = .5
  ) +
  geom_line(linewidth = 1, show.legend = F, alpha = .5) +
  scale_y_continuous(limits = c(50, 70)) + 
  scale_color_manual(values = c("blue", "red")) + 
  annotate(
    "text", 
    x = .85, 
    y = pred_therm1[1, 3], 
    label = paste0(round(pred_therm1[1, 3], 3)), 
    color = "blue"
  ) +
  annotate(
    "text", 
    x = .85, 
    y = pred_therm1[3, 3], 
    label = paste0(round(pred_therm1[3, 3], 3)), 
    color = "red"
  ) +
  annotate(
    "text", 
    x = 2.2, 
    y = pred_therm1[2, 3], 
    label = paste0(round(pred_therm1[2, 3], 3)), 
    color = "blue"
  ) +
  annotate(
    "text", 
    x = 2.2, 
    y = pred_therm1[4, 3], 
    label = paste0(round(pred_therm1[4, 3], 3)), 
    color = "red"
  ) +
  annotate(
    "text", 
    x = 1.5, 
    y = .5 * (pred_therm1[2, 3] + pred_therm1[1, 3]), 
    label = paste0("+", round((pred_therm1[2, 3] - pred_therm1[1, 3]), 3)), 
    color = "blue", 
    vjust = -1, 
    fontface = 2
  ) +
  annotate(
    "text", 
    x = 1.5, 
    y = .5 * (pred_therm1[4, 3] + pred_therm1[3, 3]), 
    label = paste0("+", round((pred_therm1[4, 3] - pred_therm1[3, 3]), 3)), 
    color = "red", 
    vjust = 2, 
    fontface = 2
  ) +
  labs(
    x = "Binary Party Match", 
    title = "DV: Thermometer", 
    color = "Respondent\nParty", 
    shape = "Respondent\nParty"
  )


pred_pleased1 %>% 
  mutate(
    partyr2 = case_when(
      partyr2 == "dem" ~ "Democrats", 
      partyr2 == "rep" ~ "Republicans"
    )
  ) %>%
  ggplot(
    ., 
    aes(
      x = partymatch, 
      y = fit, 
      ymin = lwr, 
      ymax = upr, 
      color = partyr2, 
      shape = partyr2, 
      group = partyr2
    )
  ) + 
  geom_pointrange( 
    size = 1, 
    linewidth = 1, alpha = .5
  ) +
  geom_line(linewidth = 1, show.legend = F, alpha = .5) +
  scale_y_continuous(limits = c(4, 5.5)) + 
  scale_color_manual(values = c("blue", "red")) + 
  annotate(
    "text", 
    x = .85, 
    y = pred_pleased1[1, 3], 
    label = paste0(round(pred_pleased1[1, 3], 3)), 
    color = "blue"
  ) +
  annotate(
    "text", 
    x = .85, 
    y = pred_pleased1[3, 3], 
    label = paste0(round(pred_pleased1[3, 3], 3)), 
    color = "red"
  ) +
  annotate(
    "text", 
    x = 2.15, 
    y = pred_pleased1[2, 3], 
    label = paste0(round(pred_pleased1[2, 3], 3)), 
    color = "blue"
  ) +
  annotate(
    "text", 
    x = 2.15, 
    y = pred_pleased1[4, 3], 
    label = paste0(round(pred_pleased1[4, 3], 3)), 
    color = "red"
  ) +
  annotate(
    "text", 
    x = 1.5, 
    y = .5 * (pred_pleased1[2, 3] + pred_pleased1[1, 3]), 
    label = paste0("+", round((pred_pleased1[2, 3] - pred_pleased1[1, 3]), 3)), 
    color = "blue", 
    vjust = -1, 
    fontface = 2
  ) +
  annotate(
    "text", 
    x = 1.5, 
    y = .5 * (pred_pleased1[4, 3] + pred_pleased1[3, 3]), 
    label = paste0("+", round((pred_pleased1[4, 3] - pred_pleased1[3, 3]), 3)), 
    color = "red", 
    vjust = 2, 
    fontface = 2
  ) +
  labs(
    x = "Binary Party Match", 
    title = "DV: Pleased", 
    color = "Respondent\nParty", 
    shape = "Respondent\nParty"
  )

### Figure A11: Predicted Outcomes (Full Interaction) ----
new_df2 <- 
  data.frame(
    par_treatment = rep(c("Dem", "Rep"), 2), 
    partyr2 = c(rep("dem", 2), rep("rep", 2))
  )

pred2_eff <- predict(
  eff_mod7, new_df2, interval = "confidence", se.fit = TRUE
)
pred2_money <- predict(
  money_mod7, new_df2, interval = "confidence", se.fit = TRUE
)
pred2_therm <- predict(
  therm_mod7, new_df2, interval = "confidence", se.fit = TRUE
)
pred2_pleased <- predict(
  pleased_mod7, new_df2, interval = "confidence", se.fit = TRUE
)

pred_eff2 <- cbind(new_df2, pred2_eff$fit)
pred_money2 <- cbind(new_df2, pred2_money$fit)
pred_therm2 <- cbind(new_df2, pred2_therm$fit)
pred_pleased2 <- cbind(new_df2, pred2_pleased$fit)

pred_eff2$se <- pred2_eff$se.fit
pred_money2$se <- pred2_money$se.fit
pred_therm2$se <- pred2_therm$se.fit
pred_pleased2$se <- pred2_pleased$se.fit

pred_eff2$dv <- "Effectiveness"
pred_money2$dv <- "Money"
pred_therm2$dv <- "Thermometer"
pred_pleased2$dv <- "Pleased"

pred_eff2$model <- "Interaction"
pred_money2$model <- "Interaction"
pred_therm2$model <- "Interaction"
pred_pleased2$model <- "Interaction"

pred_df2 <- rbind(pred_eff2, pred_money2, pred_therm2, pred_pleased2)

{
  did_eff_m  <- (pred_eff2[1, 3] - pred_eff2[2, 3]) - (pred_eff2[4, 3] - pred_eff2[3, 3])
  did_eff_se <- sqrt( sqrt(pred_eff2[1, 6]^2 + pred_eff2[2, 6]^2)^2 + sqrt(pred_eff2[4, 6]^2 + pred_eff2[3, 6]^2)^2)
  ub_eff <- did_eff_m + 1.96 * did_eff_se
  lb_eff <- did_eff_m - 1.96 * did_eff_se
  hilo_eff <- ifelse(did_eff_m > 0, "lower", "higher")
  cong_eff <- (ub_eff > 0 & lb_eff > 0) | (ub_eff < 0 & lb_eff < 0)
  sig_eff <- ifelse(cong_eff, "", "NOT")
  cat("Republicans have a", round(-did_eff_m, 3), "[", round(lb_eff, 3), ", ", round(ub_eff, 3), "]", hilo_eff, "outcome with an inparty MC (as opposed to outparty MC) than do Democrats.\nThe difference is", sig_eff, "statistically signicant at the 0.05 level.")
}

{
  did_money_m  <- (pred_money2[1, 3] - pred_money2[2, 3]) - (pred_money2[4, 3] - pred_money2[3, 3])
  did_money_se <- sqrt( sqrt(pred_money2[1, 6]^2 + pred_money2[2, 6]^2)^2 + sqrt(pred_money2[4, 6]^2 + pred_money2[3, 6]^2)^2)
  ub_money <- did_money_m + 1.96 * did_money_se
  lb_money <- did_money_m - 1.96 * did_money_se
  hilo_money <- ifelse(did_money_m > 0, "lower", "higher")
  cong_money <- (ub_money > 0 & lb_money > 0) | (ub_money < 0 & lb_money < 0)
  sig_money <- ifelse(cong_money, "", "NOT")
  cat("Republicans have a", round(-did_money_m, 3), "[", round(lb_money, 3), ", ", round(ub_money, 3), "]", hilo_money, "outcome with an inparty MC (as opposed to outparty MC) than do Democrats.\nThe difference is", sig_money, "statistically signicant at the 0.05 level.")
}

{
  did_therm_m  <- (pred_therm2[1, 3] - pred_therm2[2, 3]) - (pred_therm2[4, 3] - pred_therm2[3, 3])
  did_therm_se <- sqrt( sqrt(pred_therm2[1, 6]^2 + pred_therm2[2, 6]^2)^2 + sqrt(pred_therm2[4, 6]^2 + pred_therm2[3, 6]^2)^2)
  ub_therm <- did_therm_m + 1.96 * did_therm_se
  lb_therm <- did_therm_m - 1.96 * did_therm_se
  hilo_therm <- ifelse(did_therm_m > 0, "lower", "higher")
  cong_therm <- (ub_therm > 0 & lb_therm > 0) | (ub_therm<0 & lb_therm<0)
  sig_therm <- ifelse(cong_therm, "", "NOT")
  cat("Republicans have a", round(-did_therm_m, 3), "[", round(lb_therm, 3), ", ", round(ub_therm, 3), "]", hilo_therm, "outcome with an inparty MC (as opposed to outparty MC) than do Democrats.\nThe difference is", sig_therm, "statistically signicant at the 0.05 level.")
}

{
  did_pleased_m  <- (pred_pleased2[1, 3] - pred_pleased2[2, 3]) - (pred_pleased2[4, 3] - pred_pleased2[3, 3])
  did_pleased_se <- sqrt( sqrt(pred_pleased2[1, 6]^2 + pred_pleased2[2, 6]^2)^2 + sqrt(pred_pleased2[4, 6]^2 + pred_pleased2[3, 6]^2)^2)
  ub_pleased <- did_pleased_m + 1.96 * did_pleased_se
  lb_pleased <- did_pleased_m - 1.96 * did_pleased_se
  hilo_pleased <- ifelse(did_pleased_m > 0, "lower", "higher")
  cong_pleased <- (ub_pleased > 0 & lb_pleased > 0) | (ub_pleased < 0 & lb_pleased < 0)
  sig_pleased <- ifelse(cong_pleased, "", "NOT")
  cat("Republicans have a", round(-did_pleased_m, 3), "[", round(lb_pleased, 3), ", ", round(ub_pleased, 3), "]", hilo_pleased, "outcome with an inparty MC (as opposed to outparty MC) than do Democrats.\nThe difference is", sig_pleased, "statistically signicant at the 0.05 level.")
}

pred_eff2 %>%
  mutate(
    partyalign = ifelse(tolower(par_treatment) == partyr2, "1", "0"), 
    partyr2 = case_when(
      partyr2 == "dem" ~ "Democrats", 
      partyr2 == "rep" ~ "Republicans")
  ) %>%
  ggplot(
    ., 
    aes(
      x = partyalign, 
      y = fit, 
      ymin = lwr, 
      ymax = upr, 
      color = partyr2, 
      shape = partyr2, 
      group = partyr2
    )
  ) + 
  geom_pointrange(
    size = 1, 
    linewidth = 1, alpha = .5
  ) +
  geom_line(size = 1, show.legend = F, alpha = .5) +
  annotate(
    "text",
    x = .85,
    y = pred_eff2[2, 3], 
    label = paste0(round(pred_eff2[2, 3], 3)), 
    color = "blue"
  ) +
  annotate(
    "text",
    x = .85,
    y = pred_eff2[3, 3], 
    label = paste0(round(pred_eff2[3, 3], 3)), 
    color = "red"
  ) +
  annotate(
    "text",
    x = 2.15,
    y = pred_eff2[1, 3], 
    label = paste0(round(pred_eff2[1, 3], 3)), 
    color = "blue", 
    vjust = -.1
  ) +
  annotate(
    "text",
    x = 2.15, 
    y = pred_eff2[4, 3], 
    label = paste0(round(pred_eff2[4, 3], 3)), 
    color = "red"
  ) +
  annotate(
    "text",
    x = 1.5,
    y = .5 * (pred_eff2[2, 3] + pred_eff2[1, 3]), 
    label = paste0("+", round((pred_eff2[1, 3] - pred_eff2[2, 3]), 3)), 
    color = "blue", 
    vjust = -1, 
    fontface = 2
  ) +
  annotate(
    "text", 
    x = 1.5, 
    y = .5 * (pred_eff2[4, 3] + pred_eff2[3, 3]), 
    label = paste0("+", round((pred_eff2[4, 3] - pred_eff2[3, 3]), 3)), 
    color = "red", 
    vjust = 2, 
    fontface = 2
  ) +
  annotate(
    "text", 
    x = 1.5, 
    y = 4.05, 
    size = 3, 
    label = paste0("Difference in effects between Dem. and Rep. respondents\nwhen treated with an inparty MC condition (difference in slopes):\n", round(did_eff_m, 3), " [", round(lb_eff, 3), ", ", round(ub_eff, 3), "]")
  ) + 
  scale_y_continuous(limits = c(4, 5.5)) + 
  scale_color_manual(values = c("blue", "red")) + 
  theme(
    legend.position = "bottom", 
    legend.key.height = unit(1, "cm"),
    legend.key.width = unit(1, "cm"), 
    legend.text = element_text(size=12)
  ) +
  labs(
    x = "", 
    title = "DV: Effectiveness", 
    color = "Respondent\nParty", 
    shape = "Respondent\nParty"
  )

pred_money2 %>% 
  mutate(
    partyalign = ifelse(tolower(par_treatment) == partyr2, "1", "0"), 
    partyr2 = case_when(
      partyr2 == "dem" ~ "Democrats", 
      partyr2 == "rep" ~ "Republicans")
  ) %>%
  ggplot(
    ., 
    aes(
      x = partyalign, 
      y = fit, 
      ymin = lwr, 
      ymax = upr,  
      color = partyr2, 
      shape = partyr2, 
      group = partyr2
    )
  ) + 
  geom_pointrange( 
    size = 1, 
    linewidth = 1, alpha = .5
  ) +
  geom_line(size = 1, show.legend = F, alpha = .5) +
  annotate(
    "text", 
    x = .85, 
    y = pred_money2[2, 3], 
    label = paste0(round(pred_money2[2, 3], 3)), 
    color = "blue"
  ) +
  annotate(
    "text", 
    x = .85, 
    y = pred_money2[3, 3], 
    label = paste0(round(pred_money2[3, 3], 3)), 
    color = "red"
  ) +
  annotate(
    "text", 
    x = 2.15, 
    y = pred_money2[1, 3], 
    label = paste0(round(pred_money2[1, 3], 3)), 
    color = "blue", 
    vjust = -.1
  ) +
  annotate(
    "text", 
    x = 2.15, 
    y = pred_money2[4, 3], 
    label = paste0(round(pred_money2[4, 3], 3)), 
    color = "red"
  ) +
  annotate(
    "text", 
    x = 1.5, 
    y = .5 * (pred_money2[2, 3] + pred_money2[1, 3]), 
    label = paste0("+", round((pred_money2[1, 3] - pred_money2[2, 3]), 3)), 
    color = "blue", 
    vjust = -1, 
    fontface = 2
  ) +
  annotate(
    "text", 
    x = 1.5, 
    y = .5 * (pred_money2[4, 3] + pred_money2[3, 3]), 
    label = paste0("+", round((pred_money2[4, 3] - pred_money2[3, 3]), 3)), 
    color = "red", 
    vjust = 2, 
    fontface = 2
  ) +
  annotate(
    "text", 
    x = 1.5, 
    y = 4.05, 
    size = 3, 
    label = paste0("Difference in effects between Dem. and Rep. respondents\nwhen treated with an inparty MC condition (difference in slopes):\n", round(did_money_m, 3), " [", round(lb_money, 3), ", ", round(ub_money, 3), "]")
  ) + 
  scale_y_continuous(limits = c(4, 5.5)) + 
  scale_color_manual(values = c("blue", "red")) + 
  theme(
    legend.position = "bottom", 
    legend.key.height = unit(1, "cm"),
    legend.key.width = unit(1, "cm"), 
    legend.text = element_text(size=12)
  ) +
  labs(
    x = "", 
    title = "DV: Money", 
    color = "Respondent\nParty", 
    shape = "Respondent\nParty"
  )

pred_therm2 %>% 
  mutate(
    partyalign = ifelse(tolower(par_treatment) == partyr2, "1", "0"), 
    partyr2 = case_when(
      partyr2 == "dem" ~ "Democrats", 
      partyr2 == "rep" ~ "Republicans"
    )
  ) %>%
  ggplot(
    ., 
    aes(
      x = partyalign, 
      y = fit, 
      ymin = lwr, 
      ymax = upr, 
      color = partyr2,  
      shape = partyr2, 
      group = partyr2
    )
  ) + 
  geom_pointrange(
    size = 1, 
    linewidth = 1, alpha = .5
  ) +
  geom_line(size = 1, show.legend = F, alpha = .5) +
  annotate(
    "text", 
    x = .85, 
    y = pred_therm2[2, 3], 
    label = paste0(round(pred_therm2[2, 3], 3)), 
    color = "blue"
  ) +
  annotate(
    "text", 
    x = .85, 
    y = pred_therm2[3, 3], 
    label = paste0(round(pred_therm2[3, 3], 3)), 
    color = "red"
  ) +
  annotate(
    "text", 
    x = 2.2, 
    y = pred_therm2[1, 3], 
    label = paste0(round(pred_therm2[1, 3], 3)), 
    color = "blue"
  ) +
  annotate(
    "text", 
    x = 2.2, 
    y = pred_therm2[4, 3], 
    label = paste0(round(pred_therm2[4, 3], 3)), 
    color = "red"
  ) +
  annotate(
    "text", 
    x = 1.5, 
    y = .5 * (pred_therm2[2, 3] + pred_therm2[1, 3]), 
    label = paste0("+", round((pred_therm2[1, 3] - pred_therm2[2, 3]), 3)), 
    color = "blue", 
    vjust = -1, 
    fontface = 2
  ) +
  annotate(
    "text", 
    x = 1.5, 
    y = .5 * (pred_therm2[4, 3] + pred_therm2[3, 3]), 
    label = paste0("+", round((pred_therm2[4, 3] - pred_therm2[3, 3]), 3)),
    color = "red", 
    vjust = 2, 
    fontface = 2
  ) +
  annotate(
    "text", 
    x = 1.5, y = 51, size =3, label = paste0("Difference in effects between Dem. and Rep. respondents\nwhen treated with an inparty MC condition (difference in slopes):\n", round(did_therm_m, 3), " [", round(lb_therm, 3), ", ", round(ub_therm, 3), "]")) + 
  scale_y_continuous(limits = c(50, 70)) + 
  scale_color_manual(values = c("blue", "red")) + 
  theme(
    legend.position = "bottom", 
    legend.key.height = unit(1, "cm"),
    legend.key.width = unit(1, "cm"), 
    legend.text = element_text(size=12)
  ) +
  labs(
    x = "Respondent-MC PID Alignment", 
    title = "DV: Thermometer", 
    color = "Respondent\nParty", 
    shape = "Respondent\nParty"
  )

pred_pleased2 %>%
  mutate(
    partyalign = ifelse(tolower(par_treatment) == partyr2, "1", "0"), 
    partyr2 = case_when(
      partyr2 == "dem" ~ "Democrats", 
      partyr2 == "rep" ~ "Republicans"
    )
  ) %>%
  ggplot(
    ., 
    aes(
      x = partyalign, 
      y = fit, 
      ymin = lwr, 
      ymax = upr, 
      color = partyr2, 
      shape = partyr2, 
      group = partyr2
    )
  ) + 
  geom_pointrange( 
    size = 1, 
    linewidth = 1, alpha = .5
  ) +
  geom_line(size = 1, show.legend = F, alpha = .5) +
  annotate(
    "text", 
    x = .85, 
    y = pred_pleased2[2, 3], 
    label = paste0(round(pred_pleased2[2, 3], 3)), 
    color = "blue"
  ) +
  annotate(
    "text", 
    x = .85, 
    y = pred_pleased2[3, 3], 
    label = paste0(round(pred_pleased2[3, 3], 3)), 
    color = "red"
  ) +
  annotate(
    "text", 
    x = 2.15, 
    y = pred_pleased2[1, 3], 
    label = paste0(round(pred_pleased2[1, 3], 3)), 
    color = "blue"
  ) +
  annotate(
    "text", 
    x = 2.15, 
    y = pred_pleased2[4, 3], 
    label = paste0(round(pred_pleased2[4, 3], 3)), 
    color = "red"
  ) +
  annotate(
    "text", 
    x = 1.5, 
    y = .5 * (pred_pleased2[2, 3] + pred_pleased2[1, 3]), 
    label = paste0("+", round((pred_pleased2[1, 3] - pred_pleased2[2, 3]), 3)), 
    color = "blue", 
    vjust = -1, 
    fontface = 2
  ) +
  annotate(
    "text", 
    x = 1.5, 
    y = .5 * (pred_pleased2[4, 3] + pred_pleased2[3, 3]), 
    label = paste0("+", round((pred_pleased2[4, 3] - pred_pleased2[3, 3]), 3)), 
    color = "red", 
    vjust = 2, 
    fontface = 2
  ) +
  annotate(
    "text", 
    x = 1.5, 
    y = 4.05, 
    size = 3, 
    label = paste0("Difference in effects between Dem. and Rep. respondents\nwhen treated with an inparty MC condition (difference in slopes):\n", round(did_pleased_m, 3), " [", round(lb_pleased, 3), ", ", round(ub_pleased, 3), "]")
  ) + 
  scale_y_continuous(limits = c(4, 5.5)) + 
  scale_color_manual(values = c("blue", "red")) + 
  theme(
    legend.position = "bottom", 
    legend.key.height = unit(1, "cm"),
    legend.key.width = unit(1, "cm"), 
    legend.text = element_text(size=12)
  ) +
  labs(
    x = "Respondent-MC PID Alignment", 
    title = "DV: Pleased", 
    color = "Respondent\nParty", 
    shape = "Respondent\nParty"
  )

## 6.5 Analysis of North Carolina Subset ----
### Figure A12: Effectiveness Ratings by Treatment Condition ----
rbind(
  ds %>%
    drop_na(effective) %>%
    group_by(pos_treatment) %>% 
    summarise(
      nrow = length(effective), 
      mean = mean(effective), 
      se = sd(effective)/sqrt(nrow),
      ci = 1.96 * se,
      lower_ci = mean - ci,
      upper_ci = mean + ci
    ) %>%
    mutate(set = "Full Sample"), 
  ds %>% 
    filter(State == "NC") %>%
    drop_na(effective) %>%
    group_by(pos_treatment) %>% 
    summarise(
      nrow = length(effective), 
      mean = mean(effective), 
      se = sd(effective) / sqrt(nrow),
      ci = 1.96 * se,
      lower_ci = mean - ci,
      upper_ci = mean + ci
    ) %>%
    mutate(set = "NC Subset")
  ) %>%
  ggplot(., aes(x = pos_treatment)) +
  geom_pointrange(
    aes(
      y = mean, 
      ymin = lower_ci, 
      ymax = upper_ci, 
      color = set, 
      shape = set
    ),
    position = position_dodge(width = 0.55), 
    size = 1, 
    linewidth = 1
  ) +
  scale_x_discrete(
    labels = c(
      "control" = "Control \n", 
      "nocom" = "No \nSubcommittee", 
      "commem" = "Subcommittee \nMember",
      "comlead" = "Subcommittee \nLeader"
    )
  ) + 
  scale_y_continuous(limits = c(3.5, 6.5)) +
  scale_shape_manual(values = c(1, 16)) + 
  scale_color_manual(values = c("grey50", "black")) +
  labs(y = "", title = "")

rbind(
  ds %>% 
    drop_na(money) %>%
    group_by(pos_treatment) %>% 
    summarise(
      nrow = length(money), 
      mean = mean(money), 
      se = sd(money) / sqrt(nrow),
      ci = 1.96 * se,
      lower_ci = mean - ci,
      upper_ci = mean + ci
    ) %>%
    mutate(set = "Full Sample"),
  ds %>% 
    filter(State == "NC") %>%
    drop_na(money) %>%
    group_by(pos_treatment) %>% 
    summarise(
      nrow = length(money), 
      mean = mean(money), 
      se = sd(money) / sqrt(nrow),
      ci = 1.96 * se,
      lower_ci = mean - ci,
      upper_ci = mean + ci
    ) %>%
    mutate(set = "NC Subset")
  ) %>%
  ggplot(., aes(x = pos_treatment)) +
  geom_pointrange(
    aes(
      y = mean, 
      ymin = lower_ci, 
      ymax = upper_ci, 
      color = set, 
      shape = set
    ),
    position = position_dodge(width = 0.25), 
    size = 1, 
    linewidth = 1
  ) +
  scale_x_discrete(
    labels = c(
      "control" = "Control \n", 
      "nocom" = "No \nSubcommittee", 
      "commem" = "Subcommittee \nMember",
      "comlead" = "Subcommittee \nLeader"
    )
  ) + 
  scale_y_continuous(limits=c(3.5, 6.5)) +
  scale_shape_manual(values = c(1, 16)) + 
  scale_color_manual(values = c("grey50", "black")) +
  labs(y = "", title = "")

### Figure A13: Support Ratings by Treatment Condition ----
rbind(
  ds %>% 
    drop_na(therm) %>%
    group_by(pos_treatment) %>% 
    summarise(
      nrow = length(therm), 
      mean = mean(therm), 
      se = sd(therm) / sqrt(nrow),
      ci = 1.96 * se,
      lower_ci = mean - ci,
      upper_ci = mean + ci) %>%
    mutate(set = "Full Sample"),
  ds %>% 
    filter(State == "NC") %>%
    drop_na(therm) %>%
    group_by(pos_treatment) %>% 
    summarise(
      nrow = length(therm), 
      mean = mean(therm), 
      se = sd(therm) / sqrt(nrow),
      ci = 1.96 * se,
      lower_ci = mean - ci,
      upper_ci = mean + ci
    ) %>%
    mutate(set = "NC Subset")
  ) %>%
  ggplot(., aes(x = pos_treatment)) +
  geom_pointrange(
    aes(
      y = mean, 
      ymin = lower_ci, 
      ymax = upper_ci, 
      color = set, 
      shape = set
    ),
    position = position_dodge(width = 0.25), 
    size = 1, 
    linewidth = 1
  ) +
  scale_x_discrete(
    labels = c(
      "control" = "Control \n",
      "nocom" = "No \nSubcommittee",
      "commem" = "Subcommittee \nMember",
      "comlead" = "Subcommittee \nLeader"
    )
  ) + 
  scale_y_continuous(limits=c(25, 75)) +
  scale_shape_manual(values = c(1, 16)) + 
  scale_color_manual(values = c("grey50", "black")) +
  labs(y = "", title = "")

rbind(
  ds %>% 
    drop_na(pleased) %>%
    group_by(pos_treatment) %>% 
    summarise(
      nrow = length(pleased), 
      mean = mean(pleased), 
      se = sd(pleased) / sqrt(nrow),
      ci = 1.96 * se,
      lower_ci = mean - ci,
      upper_ci = mean + ci
    ) %>%
    mutate(set = "Full Sample"), 
  ds %>% 
    filter(State == "NC") %>%
    drop_na(pleased) %>%
    group_by(pos_treatment) %>% 
    summarise(
      nrow = length(pleased), 
      mean = mean(pleased), 
      se = sd(pleased) / sqrt(nrow),
      ci = 1.96 * se,
      lower_ci = mean - ci,
      upper_ci = mean + ci
    ) %>%
    mutate(set = "NC Subset")
  ) %>%
  ggplot(., aes(x = pos_treatment)) +
  geom_pointrange(
    aes(
      y = mean, 
      ymin = lower_ci, 
      ymax = upper_ci, 
      color = set, 
      shape = set
    ),
    position = position_dodge(width = 0.55), 
    size = 1, 
    linewidth = 1
  ) +
  scale_x_discrete(
    labels = c(
      "control" = "Control \n", 
      "nocom" = "No \nSubcommittee", 
      "commem" = "Subcommittee \nMember",
      "comlead" = "Subcommittee \nLeader"
    )
  ) + 
  scale_y_continuous(limits=c(2.5, 7.5)) +
  scale_shape_manual(values = c(1, 16)) + 
  scale_color_manual(values = c("grey50", "black")) +
  labs(y = "", title = "")

## 6.6 Analysis of Additional Outcomes Measured ----
### Table A27: SATEs for Outcomes Measured by not Reported ----
summary(
  lm(
    responsibility ~ 
      pos_treatment_ref, 
    data = ds
  )
)

summary(
  lm(
    responsibility ~ 
      pos_treatment_ref + partymatch + partyr2 + 
      white + black + hisplat + asam + natam + rother + 
      poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
    data = ds
  )
)

summary(
  lm(
    approve ~ 
      pos_treatment_ref, 
    data = ds
  )
)

summary(
  lm(
    approve ~ 
      pos_treatment_ref + partymatch + partyr2 + 
      white + black + hisplat + asam + natam + rother + 
      poly(age, 2, raw = TRUE) + gender + edu + ideo + income, 
    data = ds
  )
)
